Skip to Content
Menu
This question has been flagged

I am working in Odoo13 I am calculating some taxes while creating my  sale order and while doing this I am successfully calculating my respective taxes.

But after saving my sale order or by confirming it all my custom tax fields disappear.


Here is my Python File code:

class SaleOrder(models.Model):
_inherit = ['sale.order']

federal_tax = fields.Float('Federal Tax', readonly=True)
state_tax = fields.Float('State Tax', readonly=True)
county_tax = fields.Float('County Tax', readonly=True)
city_tax = fields.Float('City Tax', readonly=True)
unincorporated_tax = fields.Float('Unincorporated Tax', store=True, readonly=True)

And here is my XML File:

<xpath expr="/form/sheet/notebook/page/group/group/field[@name='amount_untaxed']" position="after">
    <field name="federal_tax" attrs="{'invisible':[('federal_tax','==', 0.00)]}"/>
    <field name="state_tax" attrs="{'invisible':[('state_tax','==', 0.00)]}"/>
    <field name="county_tax" attrs="{'invisible':[('county_tax','==', 0.00)]}"/>
    <field name="city_tax" attrs="{'invisible':[('city_tax','==', 0.00)]}"/>
    <field name="unincorporated_tax" attrs="{'invisible':[('unincorporated_tax','==', 0.00)]}"/>
</xpath>
Note: After confirming my order or by saving it my custom fields value turn to 0 that is why they are disappearing but why they are turning to zero?
Avatar
Discard
Best Answer

Hello,

if you are computing this fields so,

Put force_save="1" on xml side in every fields like bellow:

<field name="federal_tax" attrs="{'invisible':[('federal_tax','==', 0.00)]}" force_save="1"/>


Avatar
Discard
Best Answer

Thats easy, in your xml code u are telling the program that the value is 0.00 so when u save it u get that value. To avoid this u should put the default value in the definition of the model.

federal_tax = fields.Float('Federal Tax', readonly=True, default='0.00')
state_tax = fields.Float('State Tax', readonly=True, default='0.00')
county_tax = fields.Float('County Tax', readonly=True, default='0.00')
city_tax = fields.Float('City Tax', readonly=True, default='0.00')
unincorporated_tax = fields.Float('Unincorporated Tax', store=True, readonly=True, default='0.00')
Avatar
Discard
Related Posts Replies Views Activity
2
Dec 24
4540
1
Nov 24
3302
2
Apr 23
18409
1
Mar 23
2549
4
Aug 24
24474