Skip to content

Commit

Permalink
[IMP] sale_loyalty_order_suggestion: Add product_id field to the wizard
Browse files Browse the repository at this point in the history
Since we cannot know which rule is being approved for the promotion to be
applicable, in case of multi-rules it may be necessary to have available
the product that makes the promotion suggestion in order to filter the
first rule that complies with that product.
  • Loading branch information
pilarvargas-tecnativa committed Mar 19, 2024
1 parent 3671951 commit 9524e09
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
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 9524e09

Please sign in to comment.