-
-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] account_payment_mode_default_account: Migration to 16.0
- Loading branch information
1 parent
150bdac
commit c6bf5b9
Showing
10 changed files
with
72 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 40 additions & 21 deletions
61
account_payment_mode_default_account/models/account_move.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,57 @@ | ||
# Copyright 2022 Camptocamp SA | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
|
||
from contextlib import contextmanager | ||
|
||
from odoo import api, models | ||
|
||
|
||
class AccountMove(models.Model): | ||
|
||
_inherit = "account.move" | ||
|
||
def _recompute_payment_terms_lines(self): | ||
if self.payment_mode_id: | ||
return super( | ||
AccountMove, | ||
self.with_context( | ||
_partner_property_account_payment_mode=self.payment_mode_id.id | ||
), | ||
)._recompute_payment_terms_lines() | ||
else: | ||
return super()._recompute_payment_terms_lines() | ||
|
||
def _get_payment_term_lines(self): | ||
self.ensure_one() | ||
return self.line_ids.filtered( | ||
lambda line: line.account_id.user_type_id.type in ("receivable", "payable") | ||
lambda line: line.account_id.account_type | ||
in ("asset_receivable", "liability_payable") | ||
) | ||
|
||
def _change_account_on_lines(self): | ||
self.ensure_one() | ||
payment_term_lines = self._get_payment_term_lines() | ||
payment_mode_id = self.payment_mode_id.id | ||
partner = self.partner_id.with_context( | ||
_partner_property_account_payment_mode=payment_mode_id | ||
) | ||
if self.is_sale_document(include_receipts=True): | ||
payment_term_lines.account_id = partner.property_account_receivable_id | ||
else: | ||
payment_term_lines.account_id = partner.property_account_payable_id | ||
|
||
@contextmanager | ||
def _sync_dynamic_line( | ||
self, | ||
existing_key_fname, | ||
needed_vals_fname, | ||
needed_dirty_fname, | ||
line_type, | ||
container, | ||
): | ||
with super()._sync_dynamic_line( | ||
existing_key_fname, | ||
needed_vals_fname, | ||
needed_dirty_fname, | ||
line_type, | ||
container, | ||
): | ||
yield | ||
if line_type == "payment_term": | ||
invoices = container.get("records") | ||
for inv in invoices: | ||
inv._change_account_on_lines() | ||
|
||
@api.onchange("payment_mode_id") | ||
def _onchange_payment_mode_id(self): | ||
if self.payment_mode_id and self.partner_id: | ||
payment_term_lines = self._get_payment_term_lines() | ||
partner = self.partner_id.with_context( | ||
_partner_property_account_payment_mode=self.payment_mode_id.id | ||
) | ||
# Retrieve account from partner. | ||
if self.is_sale_document(include_receipts=True): | ||
payment_term_lines.account_id = partner.property_account_receivable_id | ||
else: | ||
payment_term_lines.account_id = partner.property_account_payable_id | ||
self._change_account_on_lines() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
setup/account_payment_mode_default_account/odoo/addons/account_payment_mode_default_account
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../account_payment_mode_default_account |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |