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

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?
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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"/>


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

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')
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 12 24
4541
1
thg 11 24
3303
2
thg 4 23
18413
1
thg 3 23
2550
4
thg 8 24
24474