[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). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{ {
'name': 'Contract Mandate', "name": "Contract Mandate",
'summary': 'Mandate in contracts and their invoices', "summary": "Mandate in contracts and their invoices",
'version': '12.0.1.0.2', "version": "12.0.1.0.2",
'author': 'Odoo Community Association (OCA), ' "author": "Odoo Community Association (OCA), " "Tecnativa",
'Tecnativa', "website": "https://github.com/OCA/contract",
'website': 'https://github.com/OCA/contract', "depends": ["contract_payment_mode", "account_banking_mandate",],
'depends': [ "category": "Sales Management",
'contract_payment_mode', "license": "AGPL-3",
'account_banking_mandate', "data": ["views/contract_view.xml",],
], "installable": True,
'category': 'Sales Management', "auto_install": True,
'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): class ContractContract(models.Model):
_inherit = 'contract.contract' _inherit = "contract.contract"
mandate_id = fields.Many2one( mandate_id = fields.Many2one(
comodel_name='account.banking.mandate', comodel_name="account.banking.mandate",
ondelete='restrict', ondelete="restrict",
string='Direct Debit Mandate', string="Direct Debit Mandate",
help="If mandate required in payment method and not set mandate, " help="If mandate required in payment method and not set mandate, "
"invoice takes the first valid mandate", "invoice takes the first valid mandate",
index=True, index=True,
) )
mandate_required = fields.Boolean( mandate_required = fields.Boolean(
related='payment_mode_id.payment_method_id.mandate_required', related="payment_mode_id.payment_method_id.mandate_required", readonly=True
readonly=True) )
commercial_partner_id = fields.Many2one( commercial_partner_id = fields.Many2one(
related='partner_id.commercial_partner_id', related="partner_id.commercial_partner_id",
readonly=True, readonly=True,
string='Commercial Entity', string="Commercial Entity",
) )
@api.multi @api.multi
@api.onchange('payment_mode_id') @api.onchange("payment_mode_id")
def _onchange_payment_mode_id(self): def _onchange_payment_mode_id(self):
self.ensure_one() self.ensure_one()
if not self.mandate_required: if not self.mandate_required:
@@ -37,14 +37,17 @@ class ContractContract(models.Model):
date_invoice, journal=journal date_invoice, journal=journal
) )
if self.mandate_id: 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: elif self.payment_mode_id.payment_method_id.mandate_required:
mandate = self.env['account.banking.mandate'].search([ mandate = self.env["account.banking.mandate"].search(
('partner_id', '=', self.partner_id.commercial_partner_id.id), [
('state', '=', 'valid'), ("partner_id", "=", self.partner_id.commercial_partner_id.id),
('company_id', '=', self.company_id.id), ("state", "=", "valid"),
], limit=1) ("company_id", "=", self.company_id.id),
invoice_vals['mandate_id'] = mandate.id ],
limit=1,
)
invoice_vals["mandate_id"] = mandate.id
return invoice_vals return invoice_vals
@api.model @api.model
@@ -56,8 +59,7 @@ class ContractContract(models.Model):
mandates_by_invoice = {} mandates_by_invoice = {}
for invoice in invoices: for invoice in invoices:
mandates_by_invoice[invoice] = invoice.mandate_id mandates_by_invoice[invoice] = invoice.mandate_id
res = super(ContractContract, self)._finalize_invoice_creation( res = super(ContractContract, self)._finalize_invoice_creation(invoices)
invoices)
for invoice in invoices: for invoice in invoices:
invoice.mandate_id = mandates_by_invoice.get(invoice) invoice.mandate_id = mandates_by_invoice.get(invoice)
return res return res

View File

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

View File

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