Skip to content

Commit 67f0650

Browse files
committed
[MIG] account_reconcile_sale_order: Migration to 18.0
1 parent ffb5f7c commit 67f0650

15 files changed

+339
-333
lines changed

account_reconcile_sale_order/README.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ Reconcile sale orders
1717
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1818
:alt: License: AGPL-3
1919
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--reconcile-lightgray.png?logo=github
20-
:target: https://github.com/OCA/account-reconcile/tree/15.0/account_reconcile_sale_order
20+
:target: https://github.com/OCA/account-reconcile/tree/18.0/account_reconcile_sale_order
2121
:alt: OCA/account-reconcile
2222
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23-
:target: https://translation.odoo-community.org/projects/account-reconcile-15-0/account-reconcile-15-0-account_reconcile_sale_order
23+
:target: https://translation.odoo-community.org/projects/account-reconcile-18-0/account-reconcile-18-0-account_reconcile_sale_order
2424
:alt: Translate me on Weblate
2525
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26-
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-reconcile&target_branch=15.0
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-reconcile&target_branch=18.0
2727
:alt: Try me on Runboat
2828

2929
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -63,6 +63,8 @@ To use this module, you need to:
6363
*invoicable* sale order
6464
2. Enter the reconciliation screen
6565
3. Observe that the sale order is offered as reconciliation counterpart
66+
4. You can manually select and deselect sale orders in the *sale orders*
67+
tab of the reconciliation widget
6668

6769
Note the reconciliation only works if fully invoicing the sale order
6870
yields an invoice over the order's total amount. Usually this means that
@@ -75,7 +77,7 @@ Bug Tracker
7577
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-reconcile/issues>`_.
7678
In case of trouble, please check there if your issue has already been reported.
7779
If you spotted it first, help us to smash it by providing a detailed and welcomed
78-
`feedback <https://github.com/OCA/account-reconcile/issues/new?body=module:%20account_reconcile_sale_order%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
80+
`feedback <https://github.com/OCA/account-reconcile/issues/new?body=module:%20account_reconcile_sale_order%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
7981

8082
Do not contact contributors directly about support or help with technical issues.
8183

@@ -114,6 +116,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
114116

115117
|maintainer-hbrunn|
116118

117-
This module is part of the `OCA/account-reconcile <https://github.com/OCA/account-reconcile/tree/15.0/account_reconcile_sale_order>`_ project on GitHub.
119+
This module is part of the `OCA/account-reconcile <https://github.com/OCA/account-reconcile/tree/18.0/account_reconcile_sale_order>`_ project on GitHub.
118120

119121
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

account_reconcile_sale_order/__manifest__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"name": "Reconcile sale orders",
66
"summary": "Invoice and reconcile sale orders",
7-
"version": "15.0.1.0.0",
7+
"version": "18.0.1.0.0",
88
"development_status": "Alpha",
99
"category": "Accounting",
1010
"website": "https://github.com/OCA/account-reconcile",
@@ -13,17 +13,19 @@
1313
"license": "AGPL-3",
1414
"depends": [
1515
"sale",
16-
"account_reconciliation_widget",
16+
"account_reconcile_oca",
1717
],
1818
"data": [
19+
"views/account_bank_statement_line.xml",
1920
"views/account_reconcile_model.xml",
21+
"views/sale_order.xml",
2022
],
2123
"demo": [
2224
"demo/account_reconcile_model.xml",
2325
],
2426
"assets": {
2527
"web.assets_backend": [
26-
"account_reconcile_sale_order/static/src/js/*.js",
28+
"/account_reconcile_sale_order/static/src/js/account_reconcile_sale_order.*",
2729
],
2830
},
2931
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
from . import account_bank_statement_line
2-
from . import account_reconciliation_widget
32
from . import account_reconcile_model
Lines changed: 108 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,129 @@
11
# Copyright 2024 Hunki Enterprises BV
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)
33

4-
from odoo import models
4+
5+
from odoo import api, fields, models
56

67

78
class AccountBankStatementLine(models.Model):
89
_inherit = "account.bank.statement.line"
910

10-
def process_reconciliation(
11-
self, counterpart_aml_dicts=None, payment_aml_rec=None, new_aml_dicts=None
11+
add_sale_order_id = fields.Many2one(
12+
"sale.order",
13+
check_company=True,
14+
store=False,
15+
default=False,
16+
prefetch=False,
17+
)
18+
19+
@api.onchange("add_sale_order_id")
20+
def _onchange_add_sale_order_id(self):
21+
new_data = []
22+
to_add = True
23+
24+
for line in self.reconcile_data_info["data"]:
25+
if line.get("sale_order_id") == self.add_sale_order_id.id:
26+
to_add = False
27+
continue
28+
new_data.append(line)
29+
30+
if to_add:
31+
new_data.append(
32+
self._get_reconcile_line_for_sale_order(
33+
self.add_sale_order_id,
34+
"other",
35+
self.reconcile_data_info["reconcile_auxiliary_id"],
36+
)
37+
)
38+
self.reconcile_data_info["reconcile_auxiliary_id"] += 1
39+
40+
self.reconcile_data_info = self._recompute_suspense_line(
41+
new_data,
42+
self.reconcile_data_info["reconcile_auxiliary_id"],
43+
self.manual_reference,
44+
)
45+
self.can_reconcile = self.reconcile_data_info.get("can_reconcile", False)
46+
47+
def _default_reconcile_data(self, from_unreconcile=False):
48+
self = self.with_context(account_reconcile_sale_order_inject_rule_type=True)
49+
return super()._default_reconcile_data(from_unreconcile=from_unreconcile)
50+
51+
def _get_reconcile_line(
52+
self,
53+
line,
54+
kind,
55+
is_counterpart=False,
56+
max_amount=False,
57+
from_unreconcile=False,
58+
reconcile_auxiliary_id=False,
59+
move=False,
60+
is_reconciled=False,
61+
):
62+
if isinstance(line, models.Model) and line._name == "sale.order":
63+
return reconcile_auxiliary_id + len(line), [
64+
self._get_reconcile_line_for_sale_order(
65+
sale_order, kind, reconcile_auxiliary_id + i
66+
)
67+
for i, sale_order in enumerate(line)
68+
]
69+
70+
return super()._get_reconcile_line(
71+
line,
72+
kind,
73+
is_counterpart=is_counterpart,
74+
max_amount=max_amount,
75+
from_unreconcile=from_unreconcile,
76+
reconcile_auxiliary_id=reconcile_auxiliary_id,
77+
move=move,
78+
is_reconciled=is_reconciled,
79+
)
80+
81+
def _get_reconcile_line_for_sale_order(
82+
self, sale_order, kind, reconcile_auxiliary_id
1283
):
1384
"""
14-
Invoice selected sale orders and use resulting move lines
85+
Return dict to be added to reconcile_data_info["data"] for sale order
1586
"""
16-
new_aml_dicts2 = []
17-
counterpart_aml_dicts = (counterpart_aml_dicts or [])[:]
18-
for new_aml_dict in new_aml_dicts or []:
19-
sale_order_id = new_aml_dict.get("sale_order_id")
20-
if sale_order_id:
21-
order = self.env["sale.order"].browse(sale_order_id)
22-
self._process_reconciliation_sale_order_invoice(order)
23-
counterpart_aml_dicts += (
24-
self._process_reconciliation_sale_order_counterparts(order)
87+
account = sale_order.partner_id.property_account_receivable_id
88+
return {
89+
"id": False,
90+
"reference": f"reconcile_auxiliary;{reconcile_auxiliary_id}",
91+
"account_id": (account.id, self.env._("Sale Order %s", sale_order.name)),
92+
"partner_id": (
93+
sale_order.partner_id.id,
94+
sale_order.partner_id.display_name,
95+
),
96+
"date": fields.Date.to_string(sale_order.date_order),
97+
"name": sale_order.name,
98+
"amount": -sale_order.amount_total,
99+
"credit": sale_order.amount_total,
100+
"debit": 0,
101+
"kind": kind,
102+
"currency_id": sale_order.currency_id.id,
103+
"currency_amount": -sale_order.amount_total,
104+
"line_currency_id": sale_order.currency_id.id,
105+
"sale_order_id": sale_order.id,
106+
}
107+
108+
def _prepare_reconcile_line_data(self, lines):
109+
for line in lines:
110+
if line.get("sale_order_id"):
111+
sale_order = self.env["sale.order"].browse(line["sale_order_id"])
112+
counterpart_lines = (
113+
self._prepare_reconcile_line_data_sale_order_invoice(sale_order)
25114
)
26-
else:
27-
new_aml_dicts2.append(new_aml_dict)
115+
line["counterpart_line_ids"] = counterpart_lines.ids
28116

29-
return super().process_reconciliation(
30-
counterpart_aml_dicts=counterpart_aml_dicts,
31-
payment_aml_rec=payment_aml_rec,
32-
new_aml_dicts=new_aml_dicts2,
33-
)
117+
return super()._prepare_reconcile_line_data(lines)
34118

35-
def _process_reconciliation_sale_order_invoice(self, order):
119+
def _prepare_reconcile_line_data_sale_order_invoice(self, order):
36120
"""
37121
Invoice selected sale orders and post the invoices
38122
"""
39-
clean_context = {
40-
key: value
41-
for key, value in self.env.context.items()
42-
if key != "force_price_include"
43-
}
44-
order = order.with_context(clean_context) # pylint: disable=context-overridden
45123
if order.state in ("draft", "sent"):
46124
order.action_confirm()
47125
invoices = order._create_invoices()
48126
invoices.action_post()
49-
50-
def _process_reconciliation_sale_order_counterparts(self, order):
51-
"""
52-
Return counterpart aml dicts for sale order
53-
"""
54-
return [
55-
{
56-
"name": line.name,
57-
"move_line": line,
58-
"debit": line.credit,
59-
"credit": line.debit,
60-
"analytic_tag_ids": [(6, 0, line.analytic_tag_ids.ids)],
61-
}
62-
for line in order.mapped("invoice_ids.line_ids")
63-
if line.account_id.user_type_id.type == "receivable"
64-
]
127+
return invoices.line_ids.filtered(
128+
lambda x: x.account_id.account_type == "asset_receivable"
129+
)

0 commit comments

Comments
 (0)