Debian Codegraph @

addons/l10n_in_ewaybill/models/account_move.py

raw symbols SCIP
1 # Part of Odoo. See LICENSE file for full copyright and licensing details.
2
3 from odoo import api, fields, models, _
4 from odoo.exceptions import UserError
5
6
7 class AccountMove(models.Model):
8 _inherit = 'account.move'
9
10 l10n_in_ewaybill_ids = fields.One2many(
11 'l10n.in.ewaybill',
12 'account_move_id',
13 string="E-Waybill",
14 readonly=True
15 )
16 l10n_in_ewaybill_name = fields.Char(
17 "Indian Ewaybill Number",
18 compute='_compute_l10n_in_ewaybill_details'
19 )
20 l10n_in_ewaybill_expiry_date = fields.Datetime(compute='_compute_l10n_in_ewaybill_details')
21 l10n_in_ewaybill_feature_enabled = fields.Boolean(string="E-Waybill Feature Enabled", related='company_id.l10n_in_ewaybill_feature')
22
23 def _get_l10n_in_ewaybill_form_action(self):
24 return self.env.ref('l10n_in_ewaybill.l10n_in_ewaybill_form_action')._get_action_dict()
25
26 def action_l10n_in_ewaybill_create(self):
27 self.ensure_one()
28 if self.l10n_in_ewaybill_ids:
29 raise UserError(_("Ewaybill already created for this move."))
30 action = self._get_l10n_in_ewaybill_form_action()
31 action['context'] = {'default_account_move_id': self.id}
32 return action
33
34 def action_open_l10n_in_ewaybill(self):
35 self.ensure_one()
36 action = self._get_l10n_in_ewaybill_form_action()
37 action['res_id'] = self.l10n_in_ewaybill_ids and self.l10n_in_ewaybill_ids[0].id
38 return action
39
40 @api.depends('l10n_in_ewaybill_ids.state')
41 def _compute_l10n_in_ewaybill_details(self):
42 for move in self:
43 ewaybill = move.l10n_in_ewaybill_ids and move.l10n_in_ewaybill_ids[0]
44 if move.country_code == 'IN' and move.company_id.l10n_in_ewaybill_feature and ewaybill.state == 'generated':
45 move.l10n_in_ewaybill_name = ewaybill.name
46 move.l10n_in_ewaybill_expiry_date = ewaybill.ewaybill_expiry_date
47 else:
48 move.l10n_in_ewaybill_name = False
49 move.l10n_in_ewaybill_expiry_date = False