Hi,
I’m working on a RPC method to update discounts of sale lines.
I am working with sale_discount module and reading the rst file of tests [0], especially the code:
>>> line.discount_amount = Decimal('3.3333')
>>> line.unit_price
Decimal('6.6667')
>>> line.discount_rate
Decimal('0.3333')
>>> line.discount
'$3.3333'
The RPC method is the following but doesn’t work:
@classmethod
def update_line_discount(cls, lines, discount=None):
if discount and discount > _ZERO:
for line in lines:
line.discount_amount = Decimal(discount)
line.save()
I tried with the following method too but doesn’t work neither:
@classmethod
def update_line_discount(cls, lines, discount=None):
# TODO: Add compute with context sale price list
pool = Pool()
SaleLine = pool.get('sale.line')
if discount and discount > _ZERO:
for line in lines:
SaleLine.write([line], {'discount_amount': Decimal(discount)})
Any help is welcome.
[0] sale_discount/scenario_sale_discount.rst at 5.8 · tryton/sale_discount · GitHub