-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathdeltatech_dc.py
50 lines (42 loc) · 1.82 KB
/
deltatech_dc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# © 2008-2021 Deltatech
# See README.rst file on addons root folder for license details
from odoo import _, api, fields, models
class DeltatechDC(models.Model):
_name = "deltatech.dc"
_description = "Declaration of Conformity"
_order = "date desc"
name = fields.Char("Number", size=32, required=True)
date = fields.Date(
"Date of Declaration",
default=fields.Date.context_today,
required=True,
index=True,
)
product_id = fields.Many2one(
"product.product",
"Product",
required=True,
index=True,
domain=[("sale_ok", "=", "True")],
)
lot_id = fields.Many2one("stock.lot", index=True, domain="[('product_id', '=', product_id)]")
company_standard = fields.Char(related="product_id.company_standard", string="Standard of Company", store=False)
data_sheet = fields.Integer(related="product_id.data_sheet", string="Data Sheet", store=False)
technical_specification = fields.Integer(
related="product_id.technical_specification",
string="Technical Specification",
store=False,
)
standards = fields.Text(related="product_id.standards", string="Standards", store=False)
company_id = fields.Many2one("res.company", required=True, default=lambda self: self.env.company)
def _compute_display_name(self):
for dc in self:
dc.display_name = dc.product_id + " (" + dc.name + "/" + dc.date + ")"
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if "company_id" in vals:
self = self.with_company(vals["company_id"])
if vals.get("name", _("New")) == _("New"):
vals["name"] = self.env["ir.sequence"].next_by_code("declaration.conformity") or _("New")
return super().create(vals_list)