I want to add a new field as a new discount under the total field and I want to update. Thus, the amount due should be the total - new_discount. How can I add this? Can I have a full explanation or implementation for it please. Thanks
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- إدارة علاقات العملاء
- e-Commerce
- المحاسبة
- المخزون
- PoS
- Project
- MRP
لقد تم الإبلاغ عن هذا السؤال
Hello Moe,
Please find code in comment.
Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari
Please find below code it may help you to resolve this issue,
from odoo import fields, models, api
class AccountMove(models.Model):
_inherit = 'account.move'
discount_amount = fields.Float('Discount Amount')
@api.depends('amount_total', 'discount_amount')
def _compute_amount(self):
for move in self:
move.amount_due = move.amount_total - move.discount_amount
xml:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="inherit_view_move_form" model="ir.ui.view">
<field name="name">account.invoice.form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='amount_total']" position="after">
<field name="discount_amount"/>
</xpath>
</field>
</record>
</odoo>
Hi,
Try like below code.
python:
from odoo import fields, models, api
class AccountInvoice(models.Model):
_inherit = 'account.move'
discount_amount = fields.Float('Discount Amount', digits='Product Price')
amount_due = fields.Float(compute='_compute_amount_due', digits='Product Price', store=True)
@api.depends('amount_total', 'discount_amount')
def _compute_amount_due(self):
for record in self:
record.amount_due = record.amount_total - record.discount_amount
xml:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Add the discount_amount field to the invoice form view -->
<record id="account_invoice_form" model="ir.ui.view">
<field name="name">account.invoice.form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.view_invoice_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='amount_total']" position="after">
<field name="discount_amount"/>
</xpath>
</field>
</record>
</odoo>
Regards
Does this code update old invoices? If no, can you provide me with the code that helps updates them please? Thank you so much
هل أعجبك النقاش؟ لا تكن مستمعاً فقط. شاركنا!
أنشئ حساباً اليوم لتستمتع بالخصائص الحصرية، وتفاعل مع مجتمعنا الرائع!
تسجيلالمنشورات ذات الصلة | الردود | أدوات العرض | النشاط | |
---|---|---|---|---|
|
1
مارس 23
|
2514 | ||
|
1
يناير 25
|
1694 | ||
|
4
فبراير 24
|
4561 | ||
|
1
فبراير 24
|
1408 | ||
|
0
ديسمبر 23
|
1060 |