Skip to content

Commit

Permalink
[IMP] l10n_it_riba: Propagate supplier company bank account to bill
Browse files Browse the repository at this point in the history
  • Loading branch information
SirAionTech authored and OCA-git-bot committed Oct 29, 2024
1 parent 679e904 commit cadca47
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
35 changes: 35 additions & 0 deletions l10n_it_riba/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,41 @@ def _compute_open_amount(self):
states={"draft": [("readonly", False)]},
)

def _domain_riba_supplier_company_bank_id(self):
"""Allow to select bank accounts linked to the current company."""
return self.env["res.partner.bank"]._domain_riba_partner_bank_id()

riba_supplier_company_bank_id = fields.Many2one(
comodel_name="res.partner.bank",
compute="_compute_riba_supplier_company_bank_id",
domain=_domain_riba_supplier_company_bank_id,
help="Bank account used for the RiBa of this vendor bill.",
readonly=False,
states={
"posted": [
("readonly", True),
],
},
store=True,
string="Company Bank Account for Supplier",
)

@api.depends(
"is_riba_payment",
)
def _compute_riba_supplier_company_bank_id(self):
for move in self:
is_riba_payment = move.is_riba_payment
is_purchase_document = move.is_purchase_document(include_receipts=True)
partner_riba_bank_account = (
move.partner_id.property_riba_supplier_company_bank_id
)
if is_riba_payment and is_purchase_document and partner_riba_bank_account:
riba_bank_account = partner_riba_bank_account
else:
riba_bank_account = False
move.riba_supplier_company_bank_id = riba_bank_account

@api.model_create_multi
def create(self, vals_list):
invoices = super().create(vals_list)
Expand Down
23 changes: 23 additions & 0 deletions l10n_it_riba/tests/test_riba.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,3 +862,26 @@ def test_supplier_company_bank_account_domain(self):
# Assert: only the bank account of current company is found
self.assertIn(current_bank_account, bank_accounts)
self.assertNotIn(other_bank_account, bank_accounts)

def test_supplier_to_bill_company_bank_account(self):
"""A supplier has a company bank account,
it is propagated to its vendor bill."""
# Arrange
bank_account = self.company_bank
payment_term = self.payment_term1
supplier = self.partner
supplier.property_supplier_payment_term_id = payment_term
supplier.property_riba_supplier_company_bank_id = bank_account
self.assertTrue(payment_term.riba)

# Act: Create the vendor bill
bill = self.env["account.move"].create(
{
"move_type": "in_invoice",
"partner_id": supplier.id,
"invoice_payment_term_id": payment_term.id,
}
)

# Assert
self.assertEqual(bill.riba_supplier_company_bank_id, bank_account)
10 changes: 10 additions & 0 deletions l10n_it_riba/views/account_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@
attrs="{'invisible': ['|',('is_riba_payment','=', False),('move_type','!=','out_invoice')], 'required': ['&',('is_riba_payment','=', True),('move_type','=', 'out_invoice')]}"
domain="[('partner_id','=', commercial_partner_id)]"
/>
<field
name="riba_supplier_company_bank_id"
attrs="{
'invisible': [
'|',
('is_riba_payment', '=', False),
('move_type', '!=', 'in_invoice'),
],
}"
/>
<field
name="is_past_due"
string="Past Due"
Expand Down

0 comments on commit cadca47

Please sign in to comment.