Skip to Content
Menu
This question has been flagged

i have the following models,production  data is uploaded to dlc.pdata via excel without workstations with zero production so i created a function to identify missing workstations and write a value of 0 but it does not write only those not present but all .


class ProductionData(models.Model):
_name = 'dlc.pdata'
_rec_name = 'start_date'
_description = 'New Description'

name = fields.Char()
start_date = fields.Date(string="From", required=False, )
end_date = fields.Date(string="To", required=False,)
production_details_ids = fields.One2many(comodel_name="dlc.pdetails", inverse_name="production_data_id", string="Production Details", required=False, )



@api.multi
@api.model_create_multi
def process_data(self, values):
workstation = self.env['dlc.workstation']
dlc = set(workstation.search([]))
pdlc = self.env['dlc.pdetails']
domain = [('production_data_id', '=', self.id)]
pdlct = pdlc.search(domain)
workeddlc = set(a.workstation_id.ids[0] for a in pdlct if a.workstation_id.id)
for x in dlc + workeddlc:
if x not in workeddlc:
nowork2 = x.ids
for line in nowork2:
values = {
'workstation_id': line,
'production_data_id': self.id,
'card_type': 'Office Total',
'cdl': 0,
'gdl': 0,
'msl': 0,
'pdl': 0,
'sdl': 0,
'ddl': 0,
'total': 0,
}

self.env['dlc.pdetails'].create(values)


class ProductionDetails(models.Model):
_name = 'dlc.pdetails'
_rec_name = 'workstation_id'

workstation_id = fields.Many2one(comodel_name="dlc.workstation", string="DLC", required=False, )
production_data_id = fields.Many2one(comodel_name="dlc.pdata", string="Production", required=False, )
card_type = fields.Selection(string="Card Type",
selection=[('Temporary', 'Temporary'), ('Office Total', 'Office Total'),
('Permanent', 'Permanent')], required=False, )
cdl = fields.Integer(string="CDL", required=False, )
gdl = fields.Integer(string="GDL", required=False, )
msl = fields.Integer(string="MSL", required=False, )
pdl = fields.Integer(string="PDL", required=False, )
sdl = fields.Integer(string="SDL", required=False, )
ddl = fields.Integer(string="DDL", required=False, )
total = fields.Integer(string="TOTAL", required=False, )

class WorkStation(models.Model):
_name = 'dlc.workstation'
_description = 'list of work station'

name = fields.Char()
dlc_operator = fields.Many2many("dlc.personnel",string="DLC Personnel")
lga = fields.Many2one('dlc.lga')
state = fields.Many2one('dlc.states')
dlc_supervisor = fields.Many2one('dlc.personnel')
issues_ids = fields.One2many(comodel_name="dlc.issues", inverse_name="dlc_id", string="Issues", required=False, )
status = fields.Selection(string="DLC Status", selection=[('active', 'Active'), ('inactive', 'Inactive'), ], required=False, default= 'active' )
total_dlc = fields.Integer(string="Total DLCs", required=False, compute='_total_dlc')
inactive_dlc = fields.Integer(string="Inactive DLCs", required=False, compute='_inactive_dlc')
dlc_cug = fields.Char(string="DLC CUG Number")


Avatar
Discard
Related Posts Replies Views Activity
7
Jul 19
39463
0
Jul 24
186
1
May 24
252
4
Oct 20
6604
3
May 19
8644