Skip to content

Commit

Permalink
[MIG] account_payment_mode_default_account: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
LauraCForgeFlow committed Sep 20, 2024
1 parent 150bdac commit c6bf5b9
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 54 deletions.
19 changes: 7 additions & 12 deletions account_payment_mode_default_account/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ Account Payment Mode Default Account
!! source digest: sha256:5e6b935d02be3e279b161f28ed160f6a00ed4275cf053a5165a1e72435bbc874
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fbank--payment-lightgray.png?logo=github
:target: https://github.com/OCA/bank-payment/tree/14.0/account_payment_mode_default_account
:target: https://github.com/OCA/bank-payment/tree/16.0/account_payment_mode_default_account
:alt: OCA/bank-payment
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/bank-payment-14-0/bank-payment-14-0-account_payment_mode_default_account
:target: https://translation.odoo-community.org/projects/bank-payment-16-0/bank-payment-16-0-account_payment_mode_default_account
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/bank-payment&target_branch=14.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/bank-payment&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand All @@ -32,11 +32,6 @@ This module allows to define default receivable and payable accounts
on payment mode to override the account selected on the customer
when computing payment terms lines on invoices.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
Expand All @@ -48,7 +43,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/bank-payment/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/bank-payment/issues/new?body=module:%20account_payment_mode_default_account%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/bank-payment/issues/new?body=module:%20account_payment_mode_default_account%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Expand Down Expand Up @@ -78,6 +73,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/bank-payment <https://github.com/OCA/bank-payment/tree/14.0/account_payment_mode_default_account>`_ project on GitHub.
This module is part of the `OCA/bank-payment <https://github.com/OCA/bank-payment/tree/16.0/account_payment_mode_default_account>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 1 addition & 2 deletions account_payment_mode_default_account/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
{
"name": "Account Payment Mode Default Account",
"summary": "Set Receivable or Payable account according to payment mode",
"version": "14.0.1.0.0",
"development_status": "Alpha",
"version": "16.0.1.0.0",
"category": "Accounting/Accounting",
"website": "https://github.com/OCA/bank-payment",
"author": "Camptocamp, Odoo Community Association (OCA)",
Expand Down
61 changes: 40 additions & 21 deletions account_payment_mode_default_account/models/account_move.py
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()
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2022 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)

from odoo import fields, models


Expand All @@ -9,11 +10,11 @@ class AccountPaymentMode(models.Model):

default_receivable_account_id = fields.Many2one(
"account.account",
domain="[('deprecated', '=', False),('company_id', '=', company_id),('user_type_id.type', '=', 'receivable')]", # noqa
domain="[('deprecated', '=', False),('company_id', '=', company_id),('account_type', '=', 'asset_receivable')]", # noqa
help="This account will be used instead of the default one as the receivable account on invoices using this payment mode", # noqa
)
default_payable_account_id = fields.Many2one(
"account.account",
domain="[('deprecated', '=', False), ('company_id', '=', company_id),('user_type_id.type', '=', 'payable')]", # noqa
domain="[('deprecated', '=', False), ('company_id', '=', company_id),('account_type', '=', 'liability_payable')]", # noqa
help="This account will be used instead of the default one as the payable account on invoices using this payment mode", # noqa
)
5 changes: 3 additions & 2 deletions account_payment_mode_default_account/models/chart_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AccountChartTemplate(models.Model):
_inherit = "account.chart.template"

def generate_properties(self, acc_template_ref, company):
super().generate_properties(acc_template_ref, company)
res = super().generate_properties(acc_template_ref, company)
# Make sure a property with stored in its name is created as default for the company
# so that _get_multi would fetch it if the partner does not have a property itself
PropertyObj = self.env["ir.property"]
Expand All @@ -26,6 +26,7 @@ def generate_properties(self, acc_template_ref, company):
]
for chart_field, partner_field, model in todo_list:
account = self[chart_field]
value = acc_template_ref[account.id] if account else False
value = acc_template_ref[account].id if account else False
if value:
PropertyObj._set_default(partner_field, model, value, company=company)
return res
3 changes: 2 additions & 1 deletion account_payment_mode_default_account/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2022 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)

from odoo import api, fields, models


Expand Down Expand Up @@ -29,7 +30,7 @@ class ResPartner(models.Model):
property_stored_account_payable_id = fields.Many2one(
"account.account",
company_dependent=True,
string="Account payable",
string="Account Payable",
domain="[('internal_type', '=', 'payable'), ('deprecated', '=', False), ('company_id', '=', current_company_id)]", # noqa
)

Expand Down
13 changes: 3 additions & 10 deletions account_payment_mode_default_account/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -369,16 +368,10 @@ <h1 class="title">Account Payment Mode Default Account</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:5e6b935d02be3e279b161f28ed160f6a00ed4275cf053a5165a1e72435bbc874
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/bank-payment/tree/14.0/account_payment_mode_default_account"><img alt="OCA/bank-payment" src="https://img.shields.io/badge/github-OCA%2Fbank--payment-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/bank-payment-14-0/bank-payment-14-0-account_payment_mode_default_account"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/bank-payment&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/bank-payment/tree/16.0/account_payment_mode_default_account"><img alt="OCA/bank-payment" src="https://img.shields.io/badge/github-OCA%2Fbank--payment-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/bank-payment-16-0/bank-payment-16-0-account_payment_mode_default_account"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/bank-payment&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows to define default receivable and payable accounts
on payment mode to override the account selected on the customer
when computing payment terms lines on invoices.</p>
<div class="admonition important">
<p class="first admonition-title">Important</p>
<p class="last">This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
<a class="reference external" href="https://odoo-community.org/page/development-status">More details on development status</a></p>
</div>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand All @@ -396,7 +389,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/bank-payment/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/bank-payment/issues/new?body=module:%20account_payment_mode_default_account%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/bank-payment/issues/new?body=module:%20account_payment_mode_default_account%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -420,7 +413,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/bank-payment/tree/14.0/account_payment_mode_default_account">OCA/bank-payment</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/bank-payment/tree/16.0/account_payment_mode_default_account">OCA/bank-payment</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Copyright 2022 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo.tests import Form, SavepointCase

from odoo.tests import Form
from odoo.tests.common import TransactionCase

class TestAccountPaymentModeDefaultAccount(SavepointCase):

class TestAccountPaymentModeDefaultAccount(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand All @@ -13,15 +15,15 @@ def setUpClass(cls):
cls.receivable_account = cls.env["account.account"].search(
[
("company_id", "=", cls.env.company.id),
("user_type_id.type", "=", "receivable"),
("account_type", "=", "asset_receivable"),
("code", "=like", receivable_code + "%"),
],
limit=1,
)
cls.payable_account = cls.env["account.account"].search(
[
("company_id", "=", cls.env.company.id),
("user_type_id.type", "=", "payable"),
("account_type", "=", "liability_payable"),
],
limit=1,
)
Expand Down
6 changes: 6 additions & 0 deletions setup/account_payment_mode_default_account/setup.py
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,
)

0 comments on commit c6bf5b9

Please sign in to comment.