[FIX] sale_(coupon): Fix coupon reflection on invoice

The purpose of this task is to reflect the coupon discount perfectly
from sale order to invoice. This issue is already fixed in 13.0 in
commit: bb5d999 but during refactor of coupon it was removed due to
module split.

So in this commit, improve the default invoicing policy of coupon product.
The default invoicing policy should always be by ordered quantity.
Otherwise, if the user changes the default invoicing policy to
"delivered quantity", coupon won't be applied to the invoice.

closes odoo/odoo#65845

Taskid: 2303244
X-original-commit: 98a3ca3274e9829666a773d5fe79f2e695524f51
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
Krupal Oza
2021-02-09 19:33:28 +00:00
committed by Victor Feyens
parent 3d219cf548
commit 71499bbd23
2 changed files with 18 additions and 9 deletions
+13 -9
View File
@@ -87,15 +87,8 @@ class CouponProgram(models.Model):
def create(self, vals):
program = super(CouponProgram, self).create(vals)
if not vals.get('discount_line_product_id', False):
discount_line_product_id = self.env['product.product'].create({
'name': program.reward_id.display_name,
'type': 'service',
'taxes_id': False,
'supplier_taxes_id': False,
'sale_ok': False,
'purchase_ok': False,
'lst_price': 0, #Do not set a high value to avoid issue with coupon code
})
values = program._get_discount_product_values()
discount_line_product_id = self.env['product.product'].create(values)
program.write({'discount_line_product_id': discount_line_product_id.id})
return program
@@ -162,3 +155,14 @@ class CouponProgram(models.Model):
def _compute_total_order_count(self):
for program in self:
program.total_order_count = 0
def _get_discount_product_values(self):
return {
'name': self.reward_id.display_name,
'type': 'service',
'taxes_id': False,
'supplier_taxes_id': False,
'sale_ok': False,
'purchase_ok': False,
'lst_price': 0, #Do not set a high value to avoid issue with coupon code
}
@@ -169,6 +169,11 @@ class CouponProgram(models.Model):
programs += programs_curr_order._filter_not_ordered_reward_programs(order)
return programs
def _get_discount_product_values(self):
res = super()._get_discount_product_values()
res['invoice_policy'] = 'order'
return res
def _is_global_discount_program(self):
self.ensure_one()
return self.promo_applicability == 'on_current_order' and \