[19.0][MIG] agreement_rebate: Migration to 19.0#108
[19.0][MIG] agreement_rebate: Migration to 19.0#108gdgellatly wants to merge 38 commits intoOCA:19.0from
Conversation
Currently translated at 100.0% (116 of 116 strings) Translation: agreement-16.0/agreement-16.0-agreement_rebate Translate-URL: https://translation.odoo-community.org/projects/agreement-16-0/agreement-16-0-agreement_rebate/es/
…"move_type" TT47494
… invoiced before TT52964
…d twice when process the settlement in tow steps TT52964
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: agreement-18.0/agreement-18.0-agreement_rebate Translate-URL: https://translation.odoo-community.org/projects/agreement-18-0/agreement-18-0-agreement_rebate/
1. Use `default_*` context keys instead of custom ones. This actually solves an issue with the CI. 2. Drop the virtual records to prepare invoice values. That was needed to play onchanges but now all interesting fields are computed. 3. Refactor the invoice creation method to process groups in a cleaner way.
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: agreement-18.0/agreement-18.0-agreement_rebate Translate-URL: https://translation.odoo-community.org/projects/agreement-18-0/agreement-18-0-agreement_rebate/
Currently translated at 100.0% (114 of 114 strings) Translation: agreement-18.0/agreement-18.0-agreement_rebate Translate-URL: https://translation.odoo-community.org/projects/agreement-18-0/agreement-18-0-agreement_rebate/it/
Currently translated at 100.0% (114 of 114 strings) Translation: agreement-18.0/agreement-18.0-agreement_rebate Translate-URL: https://translation.odoo-community.org/projects/agreement-18-0/agreement-18-0-agreement_rebate/sv/
… taking care about it Before these changes, the value set in the “group invoices by” field was not taken into account when creating invoices. After these changes, invoices are created normally, grouped according to the selected option. In addition, an improvement has been added so that if an invoice is forced to a specific person, that value is used for grouping. When a value is selected for “Force invoice to”, the “group invoices by” option will be hidden.
552bcf6 to
41f30af
Compare
Made-with: Cursor
41f30af to
4422f17
Compare
Move the conditional item selection fields (products, templates, categories, condition, domain) into the same group as rebate_target. The separate "Select items" group with col="1" caused visual misalignment with the selection dropdown above it. Placing them in the same group keeps them properly aligned and is equally functional. Made-with: Cursor
|
Made one visual improvement, left as seperate commit so we can remove/change or backport more easily. |
dannyadair
left a comment
There was a problem hiding this comment.
Tested this, also with an extensive test suite for production data. Everything looks good.
Add standard multi-company ir.rule records for agreement.rebate.settlement and agreement.rebate.settlement.line models, restricting access to records matching the user's allowed companies. Made-with: Cursor
| domain = self._target_line_domain( | ||
| agreement_domain, agreement, line=line | ||
| ) | ||
| groups = target_model.read_group( |
There was a problem hiding this comment.
I've an issue on another migration due to this issue.
Can you pls change read_group to _read_group?
WARNING odoo py.warnings: /opt/odoo-venv/lib/python3.10/site-packages/odoo/addons/agreement_rebate/wizards/settlement_create.py:296: DeprecationWarning: Since 19.0, read_group is deprecated. Please use _read_group in the backend code or formatted_read_group for a complete formatted result
....
File "/__w/contract/contract/agreement_rebate_partner_company_group/tests/test_agreement_rebate.py", line 33, in test_create_settlement_wo_filters_global_company_group
settlement_wiz.action_create_settlement()
File "/opt/odoo-venv/lib/python3.10/site-packages/odoo/addons/agreement_rebate/wizards/settlement_create.py", line 296, in action_create_settlement
groups = target_model.read_group(
To fix the migration I would apply such fix (tested on OCA/contract#1405 migration):
- in
_prepare_settlement_line:
vals = {
"agreement_id": agreement.id,
"partner_id": group["partner_id"][0]
if "partner_id" in group
else agreement.partner_id.id,
}
should be
vals = {
"agreement_id": agreement.id,
"partner_id": group["partner_id"]
if "partner_id" in group
else agreement.partner_id.id,
}
action_create_settlementI would rewrite modern Odoo 19 way:
def action_create_settlement(self):
self.ensure_one()
Agreement = self.env["agreement"]
target_model = self._get_target_model()
orig_domain = self._prepare_target_domain()
settlement_dic = defaultdict(lambda: {"lines": []})
agreements = Agreement.search(self._prepare_agreement_domain())
for agreement in agreements:
key = self.get_settlement_key(agreement)
if key not in settlement_dic:
settlement_dic[key]["amount_rebate"] = 0.0
settlement_dic[key]["amount_invoiced"] = 0.0
settlement_dic[key]["partner_id"] = agreement.partner_id.id
agreement_domain = orig_domain + self._partner_domain(agreement)
if agreement.rebate_type == "line":
if not agreement.rebate_line_ids:
continue
for line in agreement.rebate_line_ids:
domain = self._target_line_domain(
agreement_domain, agreement, line=line
)
groups = target_model._read_group(
domain,
groupby=["partner_id"],
aggregates=["price_subtotal:sum", "__count"],
)
if not groups or (not groups[0][2] and not agreement.additional_consumption):
continue
for partner, amount_invoiced, count in groups:
group = {
"partner_id": partner.id,
"price_subtotal": amount_invoiced,
"__count": count,
}
vals = self._prepare_settlement_line(
domain, group, agreement, line=line
)
settlement_dic[key]["amount_rebate"] += vals["amount_rebate"]
settlement_dic[key]["amount_invoiced"] += vals["amount_invoiced"]
settlement_dic[key]["lines"].append((0, 0, vals))
elif agreement.rebate_type == "section_prorated":
domain = self._target_line_domain(agreement_domain, agreement)
groups = target_model._read_group(
domain,
groupby=["partner_id"],
aggregates=["price_subtotal:sum", "__count"],
)
if not groups or (not groups[0][2] and not agreement.additional_consumption):
continue
amount = groups[0][1] if groups else 0.0
for section in agreement.rebate_section_ids:
if amount < section.amount_to and amount < section.amount_from:
break
for partner, amount_invoiced, count in groups:
group = {
"partner_id": partner.id,
"price_subtotal": amount_invoiced,
"__count": count,
}
vals = self._prepare_settlement_line(
domain, group, agreement, section=section
)
settlement_dic[key]["amount_rebate"] += vals["amount_rebate"]
settlement_dic[key]["lines"].append((0, 0, vals))
settlement_dic[key]["amount_invoiced"] += amount
else:
domain = self._target_line_domain(agreement_domain, agreement)
groups = target_model._read_group(
domain,
groupby=["partner_id"],
aggregates=["price_subtotal:sum", "__count"],
)
if not groups or (not groups[0][2] and not agreement.additional_consumption):
continue
for partner, amount_invoiced, count in groups:
group = {
"partner_id": partner.id,
"price_subtotal": amount_invoiced,
"__count": count,
}
vals = self._prepare_settlement_line(domain, group, agreement)
settlement_dic[key]["lines"].append((0, 0, vals))
settlement_dic[key]["amount_rebate"] += vals["amount_rebate"]
settlement_dic[key]["amount_invoiced"] += vals["amount_invoiced"]
settlements = self._create_settlement(settlement_dic)
return settlements.action_show_settlement()
- Remove
get_agregate_fieldsand_settlement_line_break_fields. It's much easier to read the_read_grouparguments and is there any possibility these methods would be ever overriden? Why do we need those two helpers?
There was a problem hiding this comment.
Hello @gdgellatly , can you pls update this PR?
There was a problem hiding this comment.
Hi @yankinmax ,
Thank you for the review.
Firstly there is extensive reasons we would need to override those methods. The most common is a quantity based rebate. In terms of break, if you do a lot with multicompany and company groups often you need to break your lines differently.
I am extremely hesitant to update on these suggestions, they will hamper back and forward port and with no diff, honestly I don't even really know what is changed. But from what I could tell, they were breaking changes anyway that should not be taken up.
However I have done the obvious pieces.
There was a problem hiding this comment.
@yankinmax The obvious pieces broke tests, so have reverted for now. I am going to need a lot more clarity here. For your own clarity, those helper methods must remain.
7ff3887 to
ab1a9d9
Compare
Odoo 19 removed the public read_group API. Migrate to _read_group with the new (domain, groupby, aggregates) signature. A helper method converts tuple results back to dicts so _prepare_settlement_line keeps its existing public interface for downstream overrides. Also fix partner_id access: _read_group returns a recordset for many2one groupby fields, so use .id instead of [0]. Made-with: Cursor
|
Hello @gdgellatly from what I see you just need to include This is an OCA dependency. |
Depends on #99
Summary
Migration of
agreement_rebatemodule to 19.0.category_idfromres.groupsXML (field removed in v19)groups_id->group_idsrename in testsstring/expandon<group>, addeddomain="[]"to group-by filters, renamed duplicate filter nameproduct.product_category_allref in tests (removed in v19)Test plan
--test-enable