1
# -*- coding: utf-8 -*-
3
from odoo import api, models, fields
7
class ImportLog(models.Model):
9
_description = "Data import log"
12
date = fields.Datetime("date", default=fields.Datetime.now())
13
model = fields.Char('Model')
14
field = fields.Char('Field')
15
value = fields.Char('value')
17
name = fields.Char('Note')
18
wizard_id = fields.Integer('wizard_id')
19
description = fields.Text('ref')
20
type_error = fields.Char('Type')
21
filename = fields.Char('File')
22
state = fields.Selection([
24
("running", "Running"),
26
("error", "On error")], string="State",
27
index=True, default='draft')
30
def exist_one(self, model, field, value, vals={}):
31
"check if this error is register before log and return false or return id"
32
res_ids = self.env[model].search([(field, '=', value)])
36
self.exist_log(model, field, value, vals)
40
def exist_log(self, model, field, value, vals={}):
41
"Check if this log is already logged"
42
log_ids = self.search([('model', '=', model), ('field', '=', field), ('value', '=', value)])
44
vals.update({'model': model, 'field': field, 'value': value})
48
def exist_product(self, default_code):
49
"check this default code"
50
model = 'product.template'
51
field = 'default_code'
53
vals = {"name": "product", "description": value}
55
return self.exist_one(model, field, value, vals=vals)
58
def exist_product9(self, default_code):
59
"check this default code"
60
model = 'product.template'
63
vals = {"name": "product", "description": value}
64
return self.exist_one(model, field, value, vals=vals)
67
def exist_plant(self, plant_name):
69
plant_ids = self.env['mrp.plant'].search([('name', '=', plant_name)])
76
vals = {"name": "plant", "description": plant_name}
77
self.exist_log('mrp.plant', 'name', plant_name, vals=vals)
82
def exist_workshop(self, plant_name, workshop_name):
84
workshop_ids = self.env['mrp.workshop'].search([('name', '=', workshop_name)])
88
for workshop in workshop_ids:
89
if workshop.plant_id.name == plant_name:
94
vals = {"name": "workshop", "description": workshop_name + ';' + plant_name}
95
self.exist_log('mrp.workshop', 'name', workshop_name, vals=vals)
100
def exist_workcenter(self, plant_name, workshop_name, workcenter_name):
102
workcenter_ids = self.env['mrp.workcenter'].search([('name', '=', workcenter_name)])
106
for workcenter in workcenter_ids:
107
if workcenter.workshop_id.name == workshop_name and workcenter.plant_id.name == plant_name:
112
vals = {"name": "workcenter", "description": workcenter_name + '; ' + workshop_name + ';' + plant_name}
113
self.exist_log('mrp.workcenter', 'name', workcenter_name, vals=vals)
118
class ImportConfiguration(models.Model):
119
_name = "import.configuration"
120
_description = "Data import configuration"
122
configuration = fields.Text('Configuration')
123
name = fields.Char('description')
124
model_name = fields.Char('Model name')