Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
6900 Widoki

Odoo V8

I've added a global discount field that I want that I only want editable if the Public Pricelist is selected, unless the user is in the sale manager group, in which case they can edit irrespective of the pricelist selected.

.py

class sale_order(models.Model):
_inherit = 'sale.order'
    ct_global_discount = fields.Float('Global Discount')
    can_apply_discount = fields.Boolean(default=False)

@api.one
@api.onchange('pricelist_id')
def onchange_pricelist_id(self):
    if self.pricelist_id.name != 'Public Pricelist':
        self.ct_global_discount = 0
        if self.env.user.has_group('base.group_sale_manager'):
            self.can_apply_discount = True
        else:
            self.can_apply_discount = False
    else:     
        self.can_apply_discount = True

XML

<xpath expr="//group[@name='sale_total']" position="after">
<field name="can_apply_discount" invisible="1"/>
<field name="ct_global_discount" attrs="{'readonly': ['can_apply_discount', '=', False]}" />
</xpath>


I get an error that can_apply_discount does not exist. I can get this working using the old interface but can't for the life of me see how you get this working with the new API.

Awatar
Odrzuć
Autor

addition: I've also tried without @api.one but with no luck

Najlepsza odpowiedź

Hello Graham Vickrage,

I have seen your scenario you gave attrs on " ct_global_discount " field its syntax is actually wrong.
its should be like this :

<field name="ct_global_discount" attrs="{'readonly':[('can_apply_discount', '=', False)]}"/>

and also small correction, when you add new fields through .py file, must add a label (field string).
e.g:

can_apply_discount = fields.Boolean(string="Can Apply Discount?" default=False)   

Thanks

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
wrz 17
5057
1
wrz 16
8887
1
mar 15
7844
4
paź 19
9161
2
cze 17
3979