Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda

i want to show total of discounts in my total fields in invoices and quotations/sales order. can i activate it in odoo ? if not how can i compute it in a new field to take float of percentage and shows monetary?

Avatar
Buang
Jawaban Terbai

Hi,

In python:

The compute method will work when you save the form.

class SaleOrderLine(models.Model):
_inherit= 'sale.order.line'

discount_amount = fields.Float(string="Discount Amount", help="To get the discounted amount",compute='compute_discount_amount')
company_currency = fields.Many2one("res.currency", string='Currency',
related='company_id.currency_id', readonly=True,
tracking=True)

def compute_discount_amount(self):
for rec in self:
if rec.discount:
amount = rec.product_uom_qty * rec.price_unit
rec.discount_amount = (amount*rec.discount)/100

XML:

<record model="ir.ui.view" id="sale_order_view_inherit">
    <field name="name">sale.order.view.inherit1</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="arch" type="xml">
        <xpath expr="/form/sheet/notebook/page/field[@name='order_line']/tree/field[@name='discount']"
               position="after">
            <field name="discount_amount" widget="monetary" options="{'currency_field': 'company_currency'}"/>
            <field name="company_currency" invisible="1"/>
        </xpath>
    </field>
</record>




Regards

Avatar
Buang
Penulis

sorry to trouble you again would you please guide me on where exactly should i enter the python code and xml ? python in the init.py or manifest.py or any where else and xml where should i try it ?

Post Terkait Replies Tampilan Aktivitas
1
Des 24
2119
2
Mei 24
3456
1
Des 23
1958
1
Mar 24
1475
1
Jul 23
2782