Debian Codegraph @

addons/l10n_latam_check/wizards/l10n_latam_payment_register_check.py

raw symbols SCIP
1 # pylint: disable=protected-access
2 # Part of Odoo. See LICENSE file for full copyright and licensing details.
3 import logging
4
5 from odoo import models, fields, api
6 import stdnum
7
8 _logger = logging.getLogger(__name__)
9
10
11 class L10n_LatamPaymentRegisterCheck(models.TransientModel):
12 _name = 'l10n_latam.payment.register.check'
13 _description = 'Payment register check'
14 _check_company_auto = True
15
16 payment_register_id = fields.Many2one('account.payment.register', required=True, ondelete='cascade')
17 company_id = fields.Many2one(related='payment_register_id.company_id')
18 currency_id = fields.Many2one(related='payment_register_id.currency_id')
19 name = fields.Char(string='Number')
20 bank_id = fields.Many2one(
21 comodel_name='res.bank',
22 compute='_compute_bank_id', store=True, readonly=False,
23 )
24 issuer_vat = fields.Char(
25 compute='_compute_issuer_vat', store=True, readonly=False,
26 )
27 payment_date = fields.Date(readonly=False, required=True)
28 amount = fields.Monetary()
29
30 @api.onchange('name')
31 def _onchange_name(self):
32 if self.name:
33 self.name = self.name.zfill(8)
34
35 @api.depends('payment_register_id.payment_method_line_id.code', 'payment_register_id.partner_id')
36 def _compute_bank_id(self):
37 new_third_party_checks = self.filtered(lambda x: x.payment_register_id.payment_method_line_id.code == 'new_third_party_checks')
38 for rec in new_third_party_checks:
39 rec.bank_id = rec.payment_register_id.partner_id.bank_ids[:1].bank_id
40 (self - new_third_party_checks).bank_id = False
41
42 @api.depends('payment_register_id.payment_method_line_id.code', 'payment_register_id.partner_id')
43 def _compute_issuer_vat(self):
44 new_third_party_checks = self.filtered(lambda x: x.payment_register_id.payment_method_line_id.code == 'new_third_party_checks')
45 for rec in new_third_party_checks:
46 rec.issuer_vat = rec.payment_register_id.partner_id.vat
47 (self - new_third_party_checks).issuer_vat = False
48
49 @api.onchange('issuer_vat')
50 def _clean_issuer_vat(self):
51 for rec in self.filtered(lambda x: x.issuer_vat and x.company_id.country_id.code):
52 stdnum_vat = stdnum.util.get_cc_module(rec.company_id.country_id.code, 'vat')
53 if hasattr(stdnum_vat, 'compact'):
54 rec.issuer_vat = stdnum_vat.compact(rec.issuer_vat)