Skip to content

Commit

Permalink
[MIG][16.0] account_cash_discount_base: migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AnizR committed Feb 2, 2024
1 parent 086775d commit 1f69a41
Show file tree
Hide file tree
Showing 11 changed files with 702 additions and 60 deletions.
12 changes: 6 additions & 6 deletions account_cash_discount_base/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Account Cash Discount Base
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:4573713e47cbd6e2781f7100fd4e318c7f064e71bbcf96f6fb76a47e9bcdcbab
!! source digest: sha256:f058fb3d2bceb5c5c5d8edfde0ea7ccb4451d7d3a74dfecaf8f91c383c183942
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand All @@ -17,13 +17,13 @@ Account Cash Discount Base
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--payment-lightgray.png?logo=github
:target: https://github.com/OCA/account-payment/tree/14.0/account_cash_discount_base
:target: https://github.com/OCA/account-payment/tree/16.0/account_cash_discount_base
:alt: OCA/account-payment
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-payment-14-0/account-payment-14-0-account_cash_discount_base
:target: https://translation.odoo-community.org/projects/account-payment-16-0/account-payment-16-0-account_cash_discount_base
: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/account-payment&target_branch=14.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-payment&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -68,7 +68,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-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/account-payment/issues/new?body=module:%20account_cash_discount_base%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/account-payment/issues/new?body=module:%20account_cash_discount_base%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 @@ -101,6 +101,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/account-payment <https://github.com/OCA/account-payment/tree/14.0/account_cash_discount_base>`_ project on GitHub.
This module is part of the `OCA/account-payment <https://github.com/OCA/account-payment/tree/16.0/account_cash_discount_base>`_ 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_cash_discount_base/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@

{
"name": "Account Cash Discount Base",
"version": "14.0.1.0.0",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-payment",
"category": "Accounting",
"depends": ["account"],
"data": [
"views/account_move.xml",
"views/account_payment_term.xml",
"views/res_company.xml",
"reports/report_invoice.xml",
],
Expand Down
1 change: 1 addition & 0 deletions account_cash_discount_base/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import account_move
from . import account_payment_term
from . import res_company
from . import account_move_reversal
17 changes: 4 additions & 13 deletions account_cash_discount_base/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def _onchange_discount_delay(self):
)
def _onchange_partner_id(self):
old_payment_term_id = self.invoice_payment_term_id
res = super(AccountMove, self)._onchange_partner_id()
res = super()._onchange_partner_id()
if self.invoice_payment_term_id != old_payment_term_id:
# be sure to load discount options based on the payment term.
# It was not loaded when creating a vendor bill from a purchase
Expand All @@ -197,8 +197,8 @@ def _get_payment_move_lines(self):
self.ensure_one()
line_ids = []
for line in self.line_ids:
account_type = line.account_id.user_type_id.type
if account_type not in ("receivable", "payable"):
account_type = line.account_id.account_type
if account_type not in ("asset_receivable", "liability_payable"):
continue
line_ids.extend([rp.credit_move_id.id for rp in line.matched_credit_ids])
line_ids.extend([rp.debit_move_id.id for rp in line.matched_debit_ids])
Expand Down Expand Up @@ -232,13 +232,4 @@ def action_post(self):
)
% (move.id,)
)
return super(AccountMove, self).action_post()

def _reverse_move_vals(self, default_values, cancel=True):
res = super(AccountMove, self)._reverse_move_vals(default_values, cancel=cancel)
partner_id = self.partner_id
if self.move_type in DISCOUNT_ALLOWED_TYPES and partner_id:
partner = self.env["res.partner"].browse(partner_id)
payment_term = partner.property_supplier_payment_term_id
res["invoice_payment_term_id"] = payment_term.id
return res
return super().action_post()
17 changes: 17 additions & 0 deletions account_cash_discount_base/models/account_move_reversal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class AccountMoveReversal(models.TransientModel):
"""
Account move reversal wizard, it cancel an account move by reversing it.
"""

_inherit = "account.move.reversal"

def _prepare_default_reversal(self, move):
res = super()._prepare_default_reversal(move)
res["invoice_payment_term_id"] = move.invoice_payment_term_id.id
return res
25 changes: 23 additions & 2 deletions account_cash_discount_base/models/account_payment_term.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright 2018 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models
from odoo import _, api, fields, models
from odoo.exceptions import UserError


class AccountPaymentTerm(models.Model):
Expand All @@ -11,5 +12,25 @@ class AccountPaymentTerm(models.Model):
discount_percent = fields.Float(
string="Discount (%)",
digits="Discount",
compute="_compute_discount_percent",
)
discount_delay = fields.Integer(string="Discount Delay (days)")
discount_delay = fields.Integer(
string="Discount Delay (days)", compute="_compute_discount_delay"
)

@api.depends("line_ids.discount_percentage")
def _compute_discount_percent(self):
for rec in self:
rec.discount_percent = fields.first(rec.line_ids).discount_percentage or 0.0

@api.depends("line_ids.discount_days")
def _compute_discount_delay(self):
for rec in self:
rec.discount_delay = fields.first(rec.line_ids).discount_days or 0

@api.constrains("line_ids")
def check_discount(self):
if any(rec.discount_percent and len(rec.line_ids) > 1 for rec in self):
raise UserError(
_("You cannot have multiple lines on payment term with discount")
)
4 changes: 2 additions & 2 deletions account_cash_discount_base/reports/report_invoice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<odoo>
<template
id="report_invoice_document_inherit"
inherit_id="account.report_invoice_document"
inherit_id="account.document_tax_totals"
>
<xpath expr="//span[@t-field='o.amount_total']" position="after">
<xpath expr="//tr[hasclass('o_total')]//td[2]" position="inside">
<tr
name="discount_information"
t-if="o.discount_percent and o.discount_due_date and o.discount_amount"
Expand Down
8 changes: 4 additions & 4 deletions account_cash_discount_base/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ <h1 class="title">Account Cash Discount Base</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:4573713e47cbd6e2781f7100fd4e318c7f064e71bbcf96f6fb76a47e9bcdcbab
!! source digest: sha256:f058fb3d2bceb5c5c5d8edfde0ea7ccb4451d7d3a74dfecaf8f91c383c183942
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/account-payment/tree/14.0/account_cash_discount_base"><img alt="OCA/account-payment" src="https://img.shields.io/badge/github-OCA%2Faccount--payment-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/account-payment-14-0/account-payment-14-0-account_cash_discount_base"><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/account-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/account-payment/tree/16.0/account_cash_discount_base"><img alt="OCA/account-payment" src="https://img.shields.io/badge/github-OCA%2Faccount--payment-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/account-payment-16-0/account-payment-16-0-account_cash_discount_base"><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/account-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 was written to allow you to define cash discount (aka early payment discount)
on customer or supplier invoices.</p>
<p>On customer invoices, you can add a discount delay and
Expand Down Expand Up @@ -411,7 +411,7 @@ <h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-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/account-payment/issues/new?body=module:%20account_cash_discount_base%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/account-payment/issues/new?body=module:%20account_cash_discount_base%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 @@ -438,7 +438,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">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/account-payment/tree/14.0/account_cash_discount_base">OCA/account-payment</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-payment/tree/16.0/account_cash_discount_base">OCA/account-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
45 changes: 35 additions & 10 deletions account_cash_discount_base/tests/common.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Copyright 2018 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.tests.common import SavepointCase
from odoo import Command
from odoo.tests.common import TransactionCase


class TestAccountCashDiscountCommon(SavepointCase):
class TestAccountCashDiscountCommon(TransactionCase):
@classmethod
def setUpClass(cls):
super(TestAccountCashDiscountCommon, cls).setUpClass()
Expand All @@ -19,19 +20,14 @@ def setUpClass(cls):
cls.company = cls.env.ref("base.main_company")
cls.partner_agrolait = cls.env.ref("base.res_partner_2")

cls.recv_account_type = cls.env.ref("account.data_account_type_receivable")
cls.pay_account_type = cls.env.ref("account.data_account_type_payable")
cls.exp_account_type = cls.env.ref("account.data_account_type_expenses")
cls.inc_account_type = cls.env.ref("account.data_account_type_other_income")

cls.recv_account = cls.Account.search(
[("user_type_id", "=", cls.recv_account_type.id)], limit=1
[("account_type", "=", "asset_receivable")], limit=1
)
cls.pay_account = cls.Account.search(
[("user_type_id", "=", cls.pay_account_type.id)], limit=1
[("account_type", "=", "liability_payable")], limit=1
)
cls.exp_account = cls.Account.search(
[("user_type_id", "=", cls.exp_account_type.id)], limit=1
[("account_type", "=", "expense")], limit=1
)

cls.tax_10_p = cls.Tax.create(
Expand Down Expand Up @@ -67,6 +63,17 @@ def setUpClass(cls):
}
)

cls.tax_20_p = cls.Tax.create(
{
"sequence": 30,
"name": "Tax 20.0% (Percentage of Price)",
"amount": 20.0,
"amount_type": "percent",
"include_base_amount": False,
"type_tax_use": "purchase",
}
)

cls.sales_journal = cls.Journal.create(
{"name": "Sales Test", "code": "SJ-T", "type": "sale"}
)
Expand All @@ -80,3 +87,21 @@ def setUpClass(cls):
)
cls.partner_agrolait.property_account_payable_id = cls.pay_account
cls.partner_agrolait.property_supplier_payment_term_id = cls.payment_term

cls.payment_term_2_p_discount_7d = cls.env["account.payment.term"].create(
{
"name": "2% discount 7 days",
"line_ids": [
Command.create(
{
"value": "balance",
"value_amount": 0.0,
"months": 1,
"end_month": True,
"discount_percentage": 2,
"discount_days": 7,
}
)
],
}
)
Loading

0 comments on commit 1f69a41

Please sign in to comment.