Skip to content

[19.0][MIG] sale_commission_oca_product_criteria: Migration to 19.0 - #683

Open
AungKoKoLin1997 wants to merge 29 commits into
OCA:19.0from
qrtl:19.0-mig-sale_commission_oca_product_criteria
Open

[19.0][MIG] sale_commission_oca_product_criteria: Migration to 19.0#683
AungKoKoLin1997 wants to merge 29 commits into
OCA:19.0from
qrtl:19.0-mig-sale_commission_oca_product_criteria

Conversation

@AungKoKoLin1997

@AungKoKoLin1997 AungKoKoLin1997 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

This PR includes:

  • Standard migration

  • Minor fixes

  • Add optional conditions to commission items, following the same pattern
    as pricelist items:

    • per_unit: when checked on a fixed-amount rule, the amount is
      multiplied by the line quantity instead of being a flat fee.
    • min_qty: minimum quantity threshold; when several rules match at
      the same level, the highest applicable minimum quantity wins.
    • date_start / date_end: restrict a rule to a validity period,
      displayed as a daterange widget.

@qrtl QT7017

ilyasProgrammer and others added 26 commits July 23, 2026 07:31
Currently translated at 100.0% (65 of 65 strings)

Translation: commission-16.0/commission-16.0-sale_commission_product_criteria
Translate-URL: https://translation.odoo-community.org/projects/commission-16-0/commission-16-0-sale_commission_product_criteria/it/
Currently translated at 100.0% (63 of 63 strings)

Translation: commission-18.0/commission-18.0-sale_commission_oca_product_criteria
Translate-URL: https://translation.odoo-community.org/projects/commission-18-0/commission-18-0-sale_commission_oca_product_criteria/it/
Currently translated at 100.0% (63 of 63 strings)

Translation: commission-18.0/commission-18.0-sale_commission_oca_product_criteria
Translate-URL: https://translation.odoo-community.org/projects/commission-18-0/commission-18-0-sale_commission_oca_product_criteria/pt_BR/
@OCA-git-bot OCA-git-bot added series:19.0 mod:sale_commission_oca_product_criteria Module sale_commission_oca_product_criteria labels Jul 23, 2026
@AungKoKoLin1997
AungKoKoLin1997 force-pushed the 19.0-mig-sale_commission_oca_product_criteria branch from 2acae6b to 695dc85 Compare July 23, 2026 09:16

@yostashiro yostashiro left a comment

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.

@AungKoKoLin1997 Not migration issues, but can you take this chance to fix these points.

Comment thread sale_commission_oca_product_criteria/models/commission_line_mixin.py Outdated
Comment thread sale_commission_oca_product_criteria/models/account_move.py
Comment thread sale_commission_oca_product_criteria/models/sale_order.py
@AungKoKoLin1997
AungKoKoLin1997 force-pushed the 19.0-mig-sale_commission_oca_product_criteria branch 2 times, most recently from ca3e2ad to 640cf3c Compare July 28, 2026 08:23
Comment thread sale_commission_oca_product_criteria/models/sale_order.py
@AungKoKoLin1997
AungKoKoLin1997 force-pushed the 19.0-mig-sale_commission_oca_product_criteria branch 2 times, most recently from 43ca06e to 2c42a64 Compare July 28, 2026 09:47
@AungKoKoLin1997
AungKoKoLin1997 requested a review from kanda999 July 29, 2026 01:10
@AungKoKoLin1997
AungKoKoLin1997 force-pushed the 19.0-mig-sale_commission_oca_product_criteria branch 4 times, most recently from 9c56b5d to d4b5d0e Compare July 30, 2026 03:17
@AungKoKoLin1997
AungKoKoLin1997 force-pushed the 19.0-mig-sale_commission_oca_product_criteria branch from d4b5d0e to 5a14621 Compare August 14, 2026 07:20
… validity

Add optional conditions to commission items, following the same pattern
as pricelist items:

- per_unit: when checked on a fixed-amount rule, the amount is
  multiplied by the line quantity instead of being a flat fee. The
  displayed value gets a "/ unit" suffix so it can be told apart from a
  flat fee in the item list and on the settlement report.
- min_qty: minimum quantity threshold; a rule without minimum quantity
  always applies, and when several rules match at the same level, the
  highest applicable minimum quantity wins (min_qty is part of _order,
  as it is on pricelist items).
- date_start / date_end: restrict a rule to a validity period,
  displayed as a daterange widget.

Both quantities are expressed in the reference UoM of the product, as
pricelist item quantities are, so a line sold in a different UoM is
converted before being compared or multiplied. This also makes the net
amount base subtract the product cost per reference unit. Lines without
a product, which get an agent line as well, keep their own quantity.

Fixed amounts are set in the currency of the company of the item, so
they are converted into the currency of the document at the date the
item is matched against. The mismatch was already there for a flat fee,
but a per unit amount multiplies it by the quantity.

All the conditions are part of the item domain, so the best matching
item is still fetched as a single row ordered by the model. The date it
is matched against is the invoice date, or the order date converted in
the company timezone so that the stored amount doesn't depend on the
timezone of the user recomputing it. Both dates are declared in the
amount dependencies, to recompute the stored amount once they are set.

Commission items are also restricted to the companies of the user with a
record rule, as the model already carries a company.
… its access

Several defects of the module, none of them introduced by the port:

- The applied commission item and commission were only stored once a
  matching item had been found, so a line kept showing the item that was
  applied before it stopped matching (expired validity, quantity below
  the minimum) or before its commission was changed to another type,
  while its amount was already recomputed to 0. Store them through
  _set_applied_commission() for every agent line, before the early
  return.

- _get_single_commission_amount had no equivalent of the commission free
  check the base _get_commission_amount starts with, so a commission
  free product still earned on the product criteria path. The sale side
  amount did not depend on product_id.commission_free either, the way
  the invoice side already did, so it was not even recomputed.

- The type change protection was an onchange, so it only ran in the form
  view and a write coming from RPC, from an import or from an automation
  silently orphaned the applied items. Check it on write instead, on the
  records whose type the write really changes: a constraint would also
  reject an import or a data file rewriting the type with the value it
  already holds. The searches are sudoed, as an applied commission has
  to block the change even when the documents it is applied on belong to
  another company.

- _check_product_consistency did not watch applied_on, so it only ran
  because validate_values happens to inject one of the product fields in
  every one of its branches.

- _get_single_commission_amount returned None for a commission type it
  does not know, which would be stored as the amount of the line, and
  the displayed value of the item was left unassigned for it, which
  raises instead of simply displaying no value.

- The settlement report prints the fields of the applied item, and they
  are read as the user printing it, not as superuser the way the stored
  amount is. An invoicing or commission user without a sale group could
  therefore not print a settlement at all.

- Drop commission_item_action, which no menu, no binding and no code
  refers to: the menu uses commission_item_action_tree.
@AungKoKoLin1997
AungKoKoLin1997 force-pushed the 19.0-mig-sale_commission_oca_product_criteria branch from 5a14621 to 1a5ec57 Compare August 14, 2026 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:sale_commission_oca_product_criteria Module sale_commission_oca_product_criteria series:19.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.