Skip to content

[18.0][ADD] sale_margin_pricelist_computation: New module#262

Open
Andrii9090-tecnativa wants to merge 1 commit intoOCA:18.0from
Tecnativa:18.0-add-sale_margin_pricelist_computation
Open

[18.0][ADD] sale_margin_pricelist_computation: New module#262
Andrii9090-tecnativa wants to merge 1 commit intoOCA:18.0from
Tecnativa:18.0-add-sale_margin_pricelist_computation

Conversation

@Andrii9090-tecnativa
Copy link
Copy Markdown

@Andrii9090-tecnativa Andrii9090-tecnativa commented Apr 28, 2026

This module extends product pricelists to support Python-based formulas
for computing product cost and product sale price for margin calculations.
image

@pedrobaeza can you review it?

@Tecnativa
TT62183

@OCA-git-bot OCA-git-bot added mod:sale_margin_pricelist_computation Module sale_margin_pricelist_computation series:18.0 labels Apr 28, 2026
@Andrii9090-tecnativa Andrii9090-tecnativa marked this pull request as draft April 28, 2026 14:28
@Andrii9090-tecnativa Andrii9090-tecnativa force-pushed the 18.0-add-sale_margin_pricelist_computation branch from 8a8b834 to a0b8090 Compare April 28, 2026 14:32
@Andrii9090-tecnativa Andrii9090-tecnativa marked this pull request as ready for review April 28, 2026 14:36
@Andrii9090-tecnativa Andrii9090-tecnativa force-pushed the 18.0-add-sale_margin_pricelist_computation branch from a0b8090 to a3a5da7 Compare April 30, 2026 14:10
@pedrobaeza pedrobaeza added this to the 18.0 milestone Apr 30, 2026
@Andrii9090-tecnativa Andrii9090-tecnativa force-pushed the 18.0-add-sale_margin_pricelist_computation branch from a3a5da7 to 94cd816 Compare April 30, 2026 16:11
"for the purposes of margin calculation"
)

def _get_sale_margin_formula_eval_context(self):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this method is only called once, integrate it inside _eval_python_code, as itself it doesn't add value.

if rec.margin_cost_price_formula:
self._eval_python_code(rec.margin_cost_price_formula)

def _eval_python_code(self, test_string):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can put this method as an inner one inside _check_margin_formula, as standalone is not useful. Or at least, use a more specific method name.

)
return super()._compute_margin()

def _get_eval_context(self):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More specific name:

Suggested change
def _get_eval_context(self):
def _get_margin_pricelist_eval_context(self):

for line in self.filtered(
lambda line: line.pricelist_item_id.margin_sale_price_formula
):
eval_context = line._get_eval_context()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
eval_context = line._get_eval_context()
self_formula = self.filtered(
lambda line: line.pricelist_item_id.margin_sale_price_formula
)
for line in self_formula:

Comment on lines +55 to +57
self = self.filtered(
lambda line: not line.pricelist_item_id.margin_sale_price_formula
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self = self.filtered(
lambda line: not line.pricelist_item_id.margin_sale_price_formula
)
self -= self_formula

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:sale_margin_pricelist_computation Module sale_margin_pricelist_computation series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants