Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2759 Lượt xem

Hello, I am trying to add a discount on the invoice total by adding a new field and subtracting one percent out of the total, so that I can have an "Amount Due" of the : total-discount. Here is my code:

from odoo import fields, models, api

class AccountInvoiceInherit(models.Model):
_inherit = 'account.move'

one_percent_amount = fields.Float('1% Discount',compute='_compute_one_percent')
amount_residual = fields.Monetary(compute='_compute_amount_due', store=True)

@api.depends('amount_total')
def _compute_one_percent(self):
for record in self:
record.one_percent_amount = (record.amount_untaxed * 0.1)

@api.depends('amount_untaxed', 'one_percent_amount')
def _compute_amount_due(self):
for record in self:
record.amount_residual = record.amount_untaxed - record.one_percent_amount

View File:

xml version="1.0" encoding="utf-8"?>


id="account_invoice_form" model="ir.ui.view">
name="name">account.invoice.form
name="model">account.move
name="inherit_id" ref="account.view_move_form"/>
name="arch" type="xml">
expr="//field[@name='amount_total']" position="after">
name="one_percent_amount"/>





How to solve it? The code is not giving any error, but the deduction is not occuring

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

Can you please try like this,

from odoo import fields, models, api

class AccountInvoiceInherit(models.Model):
_inherit = 'account.move'

one_percent_amount = fields.Float('1% Discount',compute='_compute_one_percent')
amount_residual = fields.Monetary(compute='_compute_amount_due', store=True)

@api.depends('amount_total')
def _compute_one_percent(self):
for record in self:
record.one_percent_amount = (record.amount_total * 0.01)

@api.depends('amount_total', 'one_percent_amount')
def _compute_amount_due(self):
for record in self:
record.amount_residual = record.amount_total - record.one_percent_amount

Thanks

Ảnh đại diện
Huỷ bỏ
Tác giả

Thanks, Actually I tried this option before and it didn't give any update. Do you have another solution?

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 5 24
4863
2
thg 9 22
2335
1
thg 9 22
3186
3
thg 1 16
4768
2
thg 9 25
427