Skip to content

Commit

Permalink
Merge PR OCA#2584 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by OpenCode
  • Loading branch information
OCA-git-bot committed May 12, 2022
2 parents dcd4b52 + e79df91 commit 54fa636
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 5 deletions.
13 changes: 13 additions & 0 deletions l10n_it_ricevute_bancarie/migrations/14.0.1.0.1/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
invoices = env["account.move"].search(
[
("invoice_payment_term_id.riba", "=", True),
("riba_partner_bank_id", "=", False),
]
)
for invoice in invoices:
invoice._onchange_riba_partner_bank_id()
37 changes: 36 additions & 1 deletion l10n_it_ricevute_bancarie/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,44 @@ def _compute_is_unsolved(self):
"line_id",
"Past Due Journal Items",
)

is_unsolved = fields.Boolean(
"Is a past due invoice", compute="_compute_is_unsolved", store=True
)
is_riba_payment = fields.Boolean(
"Is C/O Payment", related="invoice_payment_term_id.riba", default=False
)

riba_partner_bank_id = fields.Many2one(
"res.partner.bank",
string="C/O Bank Account",
help="Bank Account Number to which the C/O will be debited. "
"If not set, first bank in partner will be used.",
readonly=True,
states={"draft": [("readonly", False)]},
)

@api.model
def create(self, vals):
invoice = super().create(vals)
if not invoice.riba_partner_bank_id:
invoice._onchange_riba_partner_bank_id()
return invoice

@api.onchange("partner_id", "invoice_payment_term_id", "move_type")
def _onchange_riba_partner_bank_id(self):
if (
not self.riba_partner_bank_id
or self.riba_partner_bank_id not in self.partner_id.bank_ids
):
bank_ids = self.env["res.partner.bank"]
if (
self.partner_id
and self.invoice_payment_term_id.riba
and self.move_type in ["out_invoice", "out_refund"]
):
bank_ids = self.partner_id.bank_ids
self.riba_partner_bank_id = bank_ids[0] if bank_ids else None

def month_check(self, invoice_date_due, all_date_due):
"""
Expand Down Expand Up @@ -226,7 +261,7 @@ class AccountMoveLine(models.Model):
"Past Due Invoices",
)
iban = fields.Char(
related="partner_id.bank_ids.acc_number", string="IBAN", store=False
related="move_id.riba_partner_bank_id.acc_number", string="IBAN", store=False
)
due_cost_line = fields.Boolean("C/O Collection Fees Line")

Expand Down
1 change: 1 addition & 0 deletions l10n_it_ricevute_bancarie/tests/riba_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def _create_invoice(self):
"journal_id": self.sale_journal.id,
"partner_id": self.partner.id,
"invoice_payment_term_id": self.payment_term1.id,
"riba_partner_bank_id": self.partner.bank_ids[0].id,
"invoice_line_ids": [
(
0,
Expand Down
5 changes: 5 additions & 0 deletions l10n_it_ricevute_bancarie/tests/test_riba.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def test_riba_flow(self):
],
}
)
invoice._onchange_riba_partner_bank_id()
invoice.action_post()
riba_move_line_id = False
for move_line in invoice.line_ids:
Expand Down Expand Up @@ -269,6 +270,7 @@ def test_unsolved_riba(self):
],
}
)
invoice._onchange_riba_partner_bank_id()
invoice.action_post()
for move_line in invoice.line_ids:
if move_line.account_id.id == self.account_rec1_id.id:
Expand Down Expand Up @@ -399,6 +401,7 @@ def test_riba_fatturapa(self):
],
}
)
invoice._onchange_riba_partner_bank_id()
invoice.action_post()
# issue wizard
riba_move_line_id = invoice.line_ids.filtered(
Expand Down Expand Up @@ -462,6 +465,7 @@ def test_riba_fatturapa_group(self):
],
}
)
invoice._onchange_riba_partner_bank_id()
invoice.action_post()
invoice1 = self.env["account.move"].create(
{
Expand Down Expand Up @@ -497,6 +501,7 @@ def test_riba_fatturapa_group(self):
],
}
)
invoice1._onchange_riba_partner_bank_id()
invoice1.action_post()
# issue wizard
riba_move_line_id = invoice.line_ids.filtered(
Expand Down
6 changes: 6 additions & 0 deletions l10n_it_ricevute_bancarie/views/account_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@
<field name="inherit_id" ref="account.view_move_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='invoice_payment_term_id']" position="after">
<field name="is_riba_payment" invisible="1" />
<field
name="riba_partner_bank_id"
attrs="{'invisible': ['|',('is_riba_payment','=', False),('move_type','!=','out_invoice')], 'required': ['&amp;',('is_riba_payment','=', True),('move_type','=', 'out_invoice')]}"
domain="[('partner_id','=', partner_id)]"
/>
<field
name="is_unsolved"
string="Past Due"
Expand Down
8 changes: 4 additions & 4 deletions l10n_it_ricevute_bancarie/wizard/wizard_riba_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ def create_rdl(
countme = 1

for move_line in move_lines:
if move_line.partner_id.bank_ids:
bank_id = move_line.partner_id.bank_ids[0]
if move_line.move_id.riba_partner_bank_id:
bank_id = move_line.move_id.riba_partner_bank_id
else:
raise exceptions.Warning(
_("No bank has been specified for partner %s!")
% move_line.partner_id.name
_("No bank has been specified for invoice %s")
% move_line.move_id.name
)
if move_line.partner_id.group_riba and do_group_riba:
for key in grouped_lines:
Expand Down

0 comments on commit 54fa636

Please sign in to comment.