Skip to content

Commit

Permalink
Merge PR #205 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Mar 20, 2024
2 parents 034844c + 9524e09 commit 731930f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
19 changes: 14 additions & 5 deletions sale_loyalty_order_suggestion/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,28 @@ def _get_available_programs(self):
]
return programs.filtered(lambda p: p.id not in programs_to_delete)

def _available_programs(self):
self.ensure_one()
def _filter_programs_by_rules_with_products(self):
"""Hook method. The objective of this method is to filter by rules that establish
products as criteria in a loyalty program and then in other methods make the
filtering that corresponds to each functionality."""
valid_programs = self._get_available_programs()
# Filters programs that have rules with minimum_qty > 0
programs_with_minimum_qty = valid_programs.filtered(
lambda x: any(rule.minimum_qty > 0 for rule in x.rule_ids)
)
return programs_with_minimum_qty

def _available_programs(self):
self.ensure_one()
filtered_programs = self._filter_programs_by_rules_with_products()
programs = self.env["loyalty.program"]
if programs_with_minimum_qty:
if filtered_programs:
product_id = self.env.context.get("product_id")
programs += programs_with_minimum_qty.filtered(
programs += filtered_programs.filtered(
lambda x: any(
product_id in rule._get_valid_products().ids for rule in x.rule_ids
product_id in rule._get_valid_products().ids
and rule.minimum_qty > 0
for rule in x.rule_ids
)
)
return programs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ export class SuggestPromotionWidget extends Component {
}

async viewPromotionsWizard() {
const productId = this.props.record.data.product_id[0];
const SuggestedPromotions = this.getSuggestedPromotions();
const record = this.__owl__.parent.parent.parent.props.record;
await record.save();
this.actionService.doAction("sale_loyalty.sale_loyalty_reward_wizard_action", {
additionalContext: {
default_active_id: record.data.id,
default_order_id: record.data.id,
default_product_id: productId,
default_reward_ids: SuggestedPromotions,
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class SaleLoyaltyRewardWizard(models.TransientModel):
_inherit = "sale.loyalty.reward.wizard"
_description = "Sale Loyalty - Reward Selection Wizard"

product_id = fields.Many2one("product.product")
# To ensure whether the selected promotion satisfies your rules and is directly
# applicable or needs to satisfy your rules to be applied.
applicable_program = fields.Boolean(
Expand Down Expand Up @@ -34,6 +35,7 @@ def _compute_applicable_promotion(self):

@api.depends("selected_reward_id")
def _compute_loyalty_rule_line_ids(self):
self.loyalty_rule_line_ids = None
units_required = min(
self.selected_reward_id.program_id.rule_ids.mapped("minimum_qty"), default=0
)
Expand Down Expand Up @@ -65,8 +67,6 @@ def _compute_loyalty_rule_line_ids(self):
)
)
self.loyalty_rule_line_ids = lines_vals
else:
self.loyalty_rule_line_ids = None

@api.depends_context("lang")
@api.depends("selected_reward_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/>
<field name="arch" type="xml">
<field name="selected_product_id" position="after">
<field name="product_id" invisible="1" />
<field name="applicable_program" invisible="1" />
<field
name="loyalty_rule_line_description"
Expand Down

0 comments on commit 731930f

Please sign in to comment.