[ADD] pos_sale_loyalty: link between pos_sale and pos_loyalty

This link module corrects some behaviors when both modules are installed and used.
The loyalty programs of quotations and sales orders are properly handled by the Sale app
and its corresponding loyalty module. Even when it is settled by the Point of Sale app,
it is still properly being handled by the Sale loyalty module and it should continue as such.
The loyalty programs of Point of Sale is not considering the order lines created by a
quotation or sale order.

closes odoo/odoo#99756

Signed-off-by: Masereel Pierre <pim@odoo.com>
This commit is contained in:
Jacky (trj)
2022-09-09 14:41:22 +02:00
parent a13df0a3a6
commit 100ad56111
7 changed files with 83 additions and 4 deletions
+9 -3
View File
@@ -230,6 +230,10 @@ const PosLoyaltyOrderline = (Orderline) => class PosLoyaltyOrderline extends Ord
}
return super.set_quantity(...arguments);
}
//to override
ignoreLoyaltyPoints() {
return false;
}
}
Registries.Model.extend(Orderline, PosLoyaltyOrderline);
@@ -753,8 +757,9 @@ const PosLoyaltyOrder = (Order) => class PosLoyaltyOrder extends Order {
let orderedProductPaid = 0;
for (const line of orderLines) {
if ((!line.reward_product_id && (rule.any_product || rule.valid_product_ids.has(line.get_product().id))) ||
(line.reward_product_id && (rule.any_product || rule.valid_product_ids.has(line.reward_product_id)))) {
if (((!line.reward_product_id && (rule.any_product || rule.valid_product_ids.has(line.get_product().id))) ||
(line.reward_product_id && (rule.any_product || rule.valid_product_ids.has(line.reward_product_id)))) &&
!line.ignoreLoyaltyPoints()){
// We only count reward products from the same program to avoid unwanted feedback loops
if (line.reward_product_id) {
const reward = this.pos.reward_by_id[line.reward_id];
@@ -781,7 +786,8 @@ const PosLoyaltyOrder = (Order) => class PosLoyaltyOrder extends Order {
splitPoints.push(...Array.apply(null, Array(totalProductQty)).map((_) => {return {points: rule.reward_point_amount}}));
} else if (rule.reward_point_mode === 'money') {
for (const line of orderLines) {
if (line.is_reward_line || !(rule.valid_product_ids.has(line.get_product().id)) || line.get_quantity() <= 0) {
if (line.is_reward_line || !(rule.valid_product_ids.has(line.get_product().id)) || line.get_quantity() <= 0
|| line.ignoreLoyaltyPoints()) {
continue;
}
const pointsPerUnit = round_precision(rule.reward_point_amount * line.get_price_with_tax() / line.get_quantity(), 0.01);
+4 -1
View File
@@ -52,8 +52,11 @@ class SaleOrderLine(models.Model):
for sale_line in self:
sale_line.qty_invoiced += sum([self._convert_qty(sale_line, pos_line.qty, 'p2s') for pos_line in sale_line.pos_order_line_ids], 0)
def _get_sale_order_fields(self):
return ["product_id", "name", "price_unit", "product_uom_qty", "tax_id", "qty_delivered", "qty_invoiced", "discount", "qty_to_invoice", "price_total"]
def read_converted(self):
field_names = ["product_id", "name", "price_unit", "product_uom_qty", "tax_id", "qty_delivered", "qty_invoiced", "discount", "qty_to_invoice", "price_total"]
field_names = self._get_sale_order_fields()
results = []
for sale_line in self:
if sale_line.product_type:
+4
View File
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import models
+23
View File
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name': 'pos_sale_loyalty',
'version': '1.0',
'category': 'Hidden',
'sequence': 6,
'summary': 'Link module between pos_sale and pos_loyalty',
'description': """
This module correct some behaviors when both module are installed.
""",
'depends': ['pos_sale', 'pos_loyalty'],
'installable': True,
'auto_install': True,
'assets': {
'point_of_sale.assets': [
'pos_sale_loyalty/static/src/js/**/*.js',
],
},
'license': 'LGPL-3',
}
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import sale_order
@@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
def _get_sale_order_fields(self):
field_names = super()._get_sale_order_fields()
field_names.append('reward_id')
return field_names
@@ -0,0 +1,26 @@
/** @odoo-module alias=pos_sale_loyalty.models **/
import { Orderline } from 'point_of_sale.models';
import Registries from 'point_of_sale.Registries';
export const PosSaleLoyaltyOrderline = (Orderline) => class PosSaleLoyaltyOrderline extends Orderline {
//@override
ignoreLoyaltyPoints() {
if (this.sale_order_origin_id) {
return true;
}
return super.ignoreLoyaltyPoints(...arguments);
}
//@override
setQuantityFromSOL(saleOrderLine) {
// we need to consider reward product such as discount in a quotation
if (saleOrderLine.reward_id) {
this.set_quantity(saleOrderLine.product_uom_qty);
} else {
super.setQuantityFromSOL(...arguments);
}
}
};
Registries.Model.extend(Orderline, PosSaleLoyaltyOrderline);