I am new to odoo and I am working on the invoice reward splitting based on seller id.
When I split the reward discount in the sale order line the write() function updates on the wrong record may be due to tax id because the default functionality was splitting the reward discount in the sale order line with only tax.
Could anyone help me out to figure out the solution?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
1
Trả lời
2274
Lượt xem
write() function works like
models.execute_kw(db, uid, password, 'model', 'write', [[id], {kwargs}])
Aren't you trying to insert a dictionary in the [id]?
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
3
thg 1 24
|
2598 | ||
|
0
thg 11 21
|
2331 | ||
|
0
thg 9 21
|
2319 | ||
|
0
thg 11 20
|
3185 | ||
|
2
thg 8 20
|
3236 |
Could you post the script of what you are actually doing?
I actually inherited the sales order with function _get_reward_values_discount to split discount reward line based on the product seller
def _get_reward_values_discount(self,program):
if program.discount_type == 'fixed_amount':
taxes = program.discount_line_product_id.taxes_id
if self.fiscal_position_id:
taxes = self.fiscal_position_id.map_tax(taxes)
return [{
'name': _("Discount: ") + program.name,
'product_id': program.discount_line_product_id.id,
'price_unit': - self._get_reward_values_discount_fixed_amount(program),
'product_uom_qty': 1.0,
'product_uom': program.discount_line_product_id.uom_id.id,
'is_reward_line': True,
'tax_id': [(4, tax.id, False) for tax in taxes],
}]
reward_dict = {}
lines = self._get_paid_order_lines()
amount_total = sum(self._get_base_order_lines(program).mapped('price_subtotal'))
if program.discount_apply_on == 'cheapest_product':
line = self._get_cheapest_line()
if line:
discount_line_amount = min(line.price_reduce * (program.discount_percentage / 100), amount_total)
if discount_line_amount:
taxes = line.tax_id
if self.fiscal_position_id:
taxes = self.fiscal_position_id.map_tax(taxes)
reward_dict[line.tax_id] = {
'name': _("Discount: ") + program.name,
'product_id': program.discount_line_product_id.id,
'price_unit': - discount_line_amount if discount_line_amount > 0 else 0,
'product_uom_qty': 1.0,
'product_uom': program.discount_line_product_id.uom_id.id,
'is_reward_line': True,
'tax_id': [(4, tax.id, False) for tax in taxes],
}
elif program.discount_apply_on in ['specific_products', 'on_order']:
if program.discount_apply_on == 'specific_products':
# We should not exclude reward line that offer this product since we need to offer only the discount on the real paid product (regular product - free product)
free_product_lines = self.env['sale.coupon.program'].search([('reward_type', '=', 'product'), ('reward_product_id', 'in', program.discount_specific_product_ids.ids)]).mapped('discount_line_product_id')
lines = lines.filtered(lambda x: x.product_id in (program.discount_specific_product_ids | free_product_lines))
# when processing lines we should not discount more than the order remaining total
currently_discounted_amount = 0
# _logger.info("**************************************************************************************************************************")
for line in lines:
discount_line_amount = min(self._get_reward_values_discount_percentage_per_line(program, line), amount_total - currently_discounted_amount)
# _logger.info(line.name)
# _logger.info(discount_line_amount)
if discount_line_amount:
_select_seller_id= line.product_id._select_seller().name.id +"-"+ str(line.tax_id.id)
if _select_seller_id in reward_dict:
reward_dict[_select_seller_id]['price_unit'] -= discount_line_amount
else:
taxes = line.tax_id
if self.fiscal_position_id:
taxes = self.fiscal_position_id.map_tax(taxes)
tax_name = ""
if len(taxes) == 1:
tax_name = " - " + _("On product with following tax: ") + ', '.join(taxes.mapped('name'))
elif len(taxes) > 1:
tax_name = " - " + _("On product with following taxes: ") + ', '.join(taxes.mapped('name'))
reward_dict[_select_seller_id] = {
'name': _("Discount: ") + program.name + tax_name + line.product_id._select_seller().name.name + str(discount_line_amount if discount_line_amount > 0 else 0),
'product_id': program.discount_line_product_id.id,
'price_unit': - discount_line_amount if discount_line_amount > 0 else 0,
'product_uom_qty': 1.0,
'product_uom': program.discount_line_product_id.uom_id.id,
'is_reward_line': True,
'tax_id': [(4, tax.id, False) for tax in taxes],
'partner_vendor_id' : line.product_id._select_seller().name.id,
}
currently_discounted_amount += discount_line_amount
_logger.info(reward_dict)
# _logger.info("**************************************************************************************************************************")
# If there is a max amount for discount, we might have to limit some discount lines or completely remove some lines
max_amount = program._compute_program_amount('discount_max_amount', self.currency_id)
if max_amount > 0:
amount_already_given = 0
for val in list(reward_dict):
amount_to_discount = amount_already_given + reward_dict[val]["price_unit"]
if abs(amount_to_discount) > max_amount:
reward_dict[val]["price_unit"] = - (max_amount - abs(amount_already_given))
add_name = formatLang(self.env, max_amount, currency_obj=self.currency_id)
reward_dict[val]["name"] += "( " + _("limited to ") + add_name + ")"
amount_already_given += reward_dict[val]["price_unit"]
if reward_dict[val]["price_unit"] == 0:
del reward_dict[val]
# _logger.info(reward_dict.values())
return reward_dict.values()