@@ -65,16 +65,16 @@ def product_id_change(self):
65
65
context_partner = dict (self .env .context , partner_id = line .order_id .partner_id .id )
66
66
if line .product_id and line .order_id .pricelist_id and self .env .user .has_group ('sale.group_discount_per_so_line' ):
67
67
pricelist_context = dict (context_partner , uom = line .product_uom .id , date = line .order_id .date_order )
68
- list_price = line .order_id .pricelist_id .with_context (pricelist_context ).price_rule_get (line .product_id .id , line .product_uom_qty or 1.0 , line .order_id .partner_id )
69
-
70
- new_list_price , currency_id = line .with_context (context_partner )._get_real_price_currency (line .product_id .id , list_price , line .product_uom_qty , line .product_uom .id , line .order_id .pricelist_id .id )
68
+ list_price_dict = line .order_id .pricelist_id .with_context (pricelist_context ).price_rule_get (line .product_id .id , line .product_uom_qty or 1.0 , line .order_id .partner_id )
69
+ list_price = list_price_dict [ line . order_id . pricelist_id . id ][ 0 ]
70
+ new_list_price , currency_id = line .with_context (context_partner )._get_real_price_currency (line .product_id .id , list_price_dict , line .product_uom_qty , line .product_uom .id , line .order_id .pricelist_id .id )
71
71
new_list_price = self .env ['account.tax' ]._fix_tax_included_price (new_list_price , line .product_id .taxes_id , line .tax_id )
72
- if line .order_id .pricelist_id .discount_policy == 'without_discount' and list_price [ line . order_id . pricelist_id . id ][ 0 ] != 0 and new_list_price != 0 :
72
+ if line .order_id .pricelist_id .discount_policy == 'without_discount' and list_price != 0 and new_list_price != 0 :
73
73
if line .product_id .company_id and line .order_id .pricelist_id .currency_id .id != line .product_id .company_id .currency_id .id :
74
74
# new_list_price is in company's currency while price in pricelist currency
75
75
ctx = dict (context_partner , date = self .order_id .date_order )
76
76
new_list_price = self .env ['res.currency' ].browse (currency_id ).with_context (ctx ).compute (new_list_price , line .order_id .pricelist_id .currency_id )
77
- discount = (new_list_price - line . price_unit ) / new_list_price * 100
77
+ discount = (new_list_price - list_price ) / new_list_price * 100
78
78
if discount > 0 :
79
79
line .price_unit = new_list_price
80
80
line .discount = discount
@@ -95,15 +95,16 @@ def product_uom_change(self):
95
95
if self .order_id .pricelist_id and self .order_id .partner_id and self .env .user .has_group ('sale.group_discount_per_so_line' ):
96
96
context_partner = dict (self .env .context , partner_id = self .order_id .partner_id .id )
97
97
pricelist_context = dict (context_partner , uom = self .product_uom .id , date = self .order_id .date_order )
98
- list_price = self .order_id .pricelist_id .with_context (pricelist_context ).price_rule_get (self .product_id .id , self .product_uom_qty or 1.0 , self .order_id .partner_id )
99
- new_list_price , currency_id = self .with_context (context_partner )._get_real_price_currency (self .product_id .id , list_price , self .product_uom_qty , self .product_uom .id , self .order_id .pricelist_id .id )
98
+ list_price_dict = self .order_id .pricelist_id .with_context (pricelist_context ).price_rule_get (self .product_id .id , self .product_uom_qty or 1.0 , self .order_id .partner_id )
99
+ list_price = list_price_dict [self .order_id .pricelist_id .id ][0 ]
100
+ new_list_price , currency_id = self .with_context (context_partner )._get_real_price_currency (self .product_id .id , list_price_dict , self .product_uom_qty , self .product_uom .id , self .order_id .pricelist_id .id )
100
101
new_list_price = self .env ['account.tax' ]._fix_tax_included_price (new_list_price , self .product_id .taxes_id , self .tax_id )
101
- if self .order_id .pricelist_id .discount_policy == 'without_discount' and list_price [ self . order_id . pricelist_id . id ][ 0 ] != 0 and new_list_price != 0 :
102
+ if self .order_id .pricelist_id .discount_policy == 'without_discount' and list_price != 0 and new_list_price != 0 :
102
103
if self .product_id .company_id and self .order_id .pricelist_id .currency_id .id != self .product_id .company_id .currency_id .id :
103
104
# new_list_price is in company's currency while price in pricelist currency
104
105
ctx = dict (context_partner , date = self .order_id .date_order )
105
106
new_list_price = self .env ['res.currency' ].browse (currency_id ).with_context (ctx ).compute (new_list_price , self .order_id .pricelist_id .currency_id )
106
- discount = (new_list_price - self . price_unit ) / new_list_price * 100
107
+ discount = (new_list_price - list_price ) / new_list_price * 100
107
108
if discount > 0 :
108
109
self .price_unit = new_list_price
109
110
self .discount = discount
0 commit comments