Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] Mostrare il conto dell'azienda per fornitori e fatture fornitore con termine di pagamento RiBa #4237

Open
wants to merge 2 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions l10n_it_riba/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ class ResPartnerBankAdd(models.Model):
help="Identification Code of the Company in the Interbank System.",
)

@api.model
def _domain_riba_partner_bank_id(self):
"""Domain to select bank accounts linked to the current company."""
company = self.env.company
return [
("partner_id", "=", company.partner_id.id),
]


class AccountMove(models.Model):
_inherit = "account.move"
Expand Down Expand Up @@ -111,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
17 changes: 17 additions & 0 deletions l10n_it_riba/models/partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,20 @@ class ResPartner(models.Model):
group_riba = fields.Boolean(
"Group RiBa", help="Group RiBa by customer while issuing."
)
is_supplier_payment_riba = fields.Boolean(
string="Is RiBa Payment",
related="property_supplier_payment_term_id.riba",
readonly=True,
)

def _domain_property_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()

property_riba_supplier_company_bank_id = fields.Many2one(
comodel_name="res.partner.bank",
company_dependent=True,
string="Company Bank Account for Supplier",
domain=_domain_property_riba_supplier_company_bank_id,
help="Bank account used for the RiBa of this supplier.",
)
46 changes: 46 additions & 0 deletions l10n_it_riba/tests/test_riba.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,3 +839,49 @@ def test_riba_payment_date_multiple_lines(self):
self.assertEqual(slip.state, "paid")
payment_move = slip.payment_ids.move_id
self.assertEqual(payment_move.date, payment_date)

def test_supplier_company_bank_account_domain(self):
"""The domain for Company Bank Account for Supplier
only shows bank accounts of current company."""
# Arrange
current_company, other_company = self.env.company, self.company2
current_bank_account = self.company_bank
other_bank_account = self.company2_bank
# pre-condition: Bank accounts belong to different companies
self.assertNotEqual(current_company, other_company)
self.assertEqual(current_bank_account.partner_id, current_company.partner_id)
self.assertEqual(other_bank_account.partner_id, other_company.partner_id)

# Act: Search bank accounts
domain = self.env["res.partner"].fields_get(
allfields=["property_riba_supplier_company_bank_id"],
attributes=["domain"],
)["property_riba_supplier_company_bank_id"]["domain"]
bank_accounts = self.env["res.partner.bank"].search(domain)

# 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
12 changes: 12 additions & 0 deletions l10n_it_riba/views/partner_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
<field name="group_riba" />
</group>
</group>
<field name="property_supplier_payment_term_id" position="after">
<field name="is_supplier_payment_riba" invisible="True" />
<field
name="property_riba_supplier_company_bank_id"
string="Company Bank Account"
attrs="{
'invisible': [
('is_supplier_payment_riba','=', False),
],
}"
/>
</field>
</field>
</record>

Expand Down
Loading