[IMP] contract_mandate: black, isort, prettier

This commit is contained in:
Guille
2020-10-21 12:28:28 +02:00
committed by hkapatel
parent dc3ac35d32
commit 0b65e09149
4 changed files with 81 additions and 77 deletions

View File

@@ -2,21 +2,15 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Contract Mandate',
'summary': 'Mandate in contracts and their invoices',
'version': '12.0.1.0.2',
'author': 'Odoo Community Association (OCA), '
'Tecnativa',
'website': 'https://github.com/OCA/contract',
'depends': [
'contract_payment_mode',
'account_banking_mandate',
],
'category': 'Sales Management',
'license': 'AGPL-3',
'data': [
'views/contract_view.xml',
],
'installable': True,
'auto_install': True,
"name": "Contract Mandate",
"summary": "Mandate in contracts and their invoices",
"version": "12.0.1.0.2",
"author": "Odoo Community Association (OCA), " "Tecnativa",
"website": "https://github.com/OCA/contract",
"depends": ["contract_payment_mode", "account_banking_mandate",],
"category": "Sales Management",
"license": "AGPL-3",
"data": ["views/contract_view.xml",],
"installable": True,
"auto_install": True,
}

View File

@@ -5,27 +5,27 @@ from odoo import api, fields, models
class ContractContract(models.Model):
_inherit = 'contract.contract'
_inherit = "contract.contract"
mandate_id = fields.Many2one(
comodel_name='account.banking.mandate',
ondelete='restrict',
string='Direct Debit Mandate',
comodel_name="account.banking.mandate",
ondelete="restrict",
string="Direct Debit Mandate",
help="If mandate required in payment method and not set mandate, "
"invoice takes the first valid mandate",
index=True,
)
mandate_required = fields.Boolean(
related='payment_mode_id.payment_method_id.mandate_required',
readonly=True)
related="payment_mode_id.payment_method_id.mandate_required", readonly=True
)
commercial_partner_id = fields.Many2one(
related='partner_id.commercial_partner_id',
related="partner_id.commercial_partner_id",
readonly=True,
string='Commercial Entity',
string="Commercial Entity",
)
@api.multi
@api.onchange('payment_mode_id')
@api.onchange("payment_mode_id")
def _onchange_payment_mode_id(self):
self.ensure_one()
if not self.mandate_required:
@@ -37,14 +37,17 @@ class ContractContract(models.Model):
date_invoice, journal=journal
)
if self.mandate_id:
invoice_vals['mandate_id'] = self.mandate_id.id
invoice_vals["mandate_id"] = self.mandate_id.id
elif self.payment_mode_id.payment_method_id.mandate_required:
mandate = self.env['account.banking.mandate'].search([
('partner_id', '=', self.partner_id.commercial_partner_id.id),
('state', '=', 'valid'),
('company_id', '=', self.company_id.id),
], limit=1)
invoice_vals['mandate_id'] = mandate.id
mandate = self.env["account.banking.mandate"].search(
[
("partner_id", "=", self.partner_id.commercial_partner_id.id),
("state", "=", "valid"),
("company_id", "=", self.company_id.id),
],
limit=1,
)
invoice_vals["mandate_id"] = mandate.id
return invoice_vals
@api.model
@@ -56,8 +59,7 @@ class ContractContract(models.Model):
mandates_by_invoice = {}
for invoice in invoices:
mandates_by_invoice[invoice] = invoice.mandate_id
res = super(ContractContract, self)._finalize_invoice_creation(
invoices)
res = super(ContractContract, self)._finalize_invoice_creation(invoices)
for invoice in invoices:
invoice.mandate_id = mandates_by_invoice.get(invoice)
return res

View File

@@ -8,36 +8,43 @@ class TestContractMandate(TestContractBase):
@classmethod
def setUpClass(cls):
super(TestContractMandate, cls).setUpClass()
cls.payment_method = cls.env['account.payment.method'].create({
'name': 'Test SDD',
'code': 'test_code_sdd',
'payment_type': 'inbound',
'mandate_required': True,
})
cls.payment_mode = cls.env['account.payment.mode'].create({
'name': 'Test payment mode',
'bank_account_link': 'variable',
'payment_method_id': cls.payment_method.id,
})
cls.partner = cls.env['res.partner'].create({
'customer': True,
'name': 'Test Customer',
'customer_payment_mode_id': cls.payment_mode.id,
})
cls.partner_bank = cls.env['res.partner.bank'].create({
'acc_number': '1234',
'partner_id': cls.partner.id,
})
cls.mandate = cls.env['account.banking.mandate'].create({
'partner_id': cls.partner.id,
'partner_bank_id': cls.partner_bank.id,
'signature_date': '2017-01-01',
})
cls.payment_method = cls.env["account.payment.method"].create(
{
"name": "Test SDD",
"code": "test_code_sdd",
"payment_type": "inbound",
"mandate_required": True,
}
)
cls.payment_mode = cls.env["account.payment.mode"].create(
{
"name": "Test payment mode",
"bank_account_link": "variable",
"payment_method_id": cls.payment_method.id,
}
)
cls.partner = cls.env["res.partner"].create(
{
"customer": True,
"name": "Test Customer",
"customer_payment_mode_id": cls.payment_mode.id,
}
)
cls.partner_bank = cls.env["res.partner.bank"].create(
{"acc_number": "1234", "partner_id": cls.partner.id,}
)
cls.mandate = cls.env["account.banking.mandate"].create(
{
"partner_id": cls.partner.id,
"partner_bank_id": cls.partner_bank.id,
"signature_date": "2017-01-01",
}
)
cls.contract_with_mandate = cls.contract2.copy(
{
'partner_id': cls.partner.id,
'payment_mode_id': cls.payment_mode.id,
'mandate_id': cls.mandate.id,
"partner_id": cls.partner.id,
"payment_mode_id": cls.payment_mode.id,
"mandate_id": cls.mandate.id,
}
)
@@ -47,11 +54,9 @@ class TestContractMandate(TestContractBase):
def test_contract_not_mandate(self):
self.contract_with_mandate.mandate_id = False
self.mandate2 = self.mandate.copy(
{'unique_mandate_reference': 'BM0000XX2'}
)
self.mandate2 = self.mandate.copy({"unique_mandate_reference": "BM0000XX2"})
self.mandate2.validate()
self.mandate.state = 'expired'
self.mandate.state = "expired"
new_invoice = self.contract_with_mandate.recurring_create_invoice()
self.assertEqual(new_invoice.mandate_id, self.mandate2)

View File

@@ -1,20 +1,23 @@
<?xml version="1.0"?>
<?xml version="1.0" ?>
<odoo>
<!--FORM view-->
<record id="contract_contract_form_view" model="ir.ui.view">
<field name="name">contract.contract form view (in contract_mandate)</field>
<field name="model">contract.contract</field>
<field name="inherit_id" ref="contract_payment_mode.contract_contract_form_view" />
<field
name="inherit_id"
ref="contract_payment_mode.contract_contract_form_view"
/>
<field name="arch" type="xml">
<field name="payment_mode_id" position="after">
<field name="mandate_id"
<field
name="mandate_id"
domain="[('partner_id', '=', commercial_partner_id), ('state', '=', 'valid')]"
attrs="{'invisible': [('mandate_required', '=', False)]}"/>
<field name="commercial_partner_id" invisible="1"/>
<field name="mandate_required" invisible="1"/>
attrs="{'invisible': [('mandate_required', '=', False)]}"
/>
<field name="commercial_partner_id" invisible="1" />
<field name="mandate_required" invisible="1" />
</field>
</field>
</record>
</odoo>