update optical_equipment

This commit is contained in:
raskolnikov 2022-11-18 13:50:53 -05:00
parent c32c506346
commit 42965ff680
5 changed files with 81 additions and 38 deletions

View File

@ -358,6 +358,10 @@ msgctxt "field:purchase.purchase,equipment_create:"
msgid "Equipments Creates" msgid "Equipments Creates"
msgstr "Equipos Creados" msgstr "Equipos Creados"
msgctxt "model:ir.model.button,string:purchase_create_equipments"
msgid "Create Equipments"
msgstr "Crear Equipos"
msgctxt "field:purchase.line,product_equipment:" msgctxt "field:purchase.line,product_equipment:"
msgid "Product Equipment" msgid "Product Equipment"
msgstr "Es Equipo" msgstr "Es Equipo"

View File

@ -13,7 +13,7 @@ from trytond.modules.product import price_digits
import datetime import datetime
from datetime import timedelta from datetime import timedelta
#from scipy.stats import t from scipy.stats import t
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
import math as mt import math as mt
@ -42,7 +42,8 @@ class MaintenanceService(Workflow, ModelSQL, ModelView):
sale_origin = fields.Reference("Sale Origin", selection='get_origin', select=True, sale_origin = fields.Reference("Sale Origin", selection='get_origin', select=True,
states={'readonly': True}) states={'readonly': True})
company = fields.Many2One('company.company', "Company", readonly=True) company = fields.Many2One('company.company', "Company", readonly=True)
maintenance_type = fields.Selection([('preventive', 'Preventive'), maintenance_type = fields.Selection([('initial','Initial'),
('preventive', 'Preventive'),
('corrective', 'Corrective') ('corrective', 'Corrective')
], "Maintenance Type", states=_states) ], "Maintenance Type", states=_states)
propietary = fields.Many2One('party.party', "Propietary", required=True, states=_states) propietary = fields.Many2One('party.party', "Propietary", required=True, states=_states)
@ -179,9 +180,9 @@ class Maintenance(Workflow, ModelSQL, ModelView):
states=_states) states=_states)
code = fields.Char( code = fields.Char(
"Code", select=True,states={'readonly': True }) "Code", select=True,states={'readonly': True })
maintenance_type = fields.Selection([('preventive', 'Preventive'), maintenance_type = fields.Selection([('initial', 'initial'),
('corrective', 'Corrective') ('preventive', 'Preventive'),
], "Maintenance Type", states=_states) ('corrective', 'Corrective')], "Maintenance Type", states=_states)
state = fields.Selection([('draft', "Draft"), state = fields.Selection([('draft', "Draft"),
('finished', "Finished") ('finished', "Finished")
], "State", readonly=True, sort=False, ], "State", readonly=True, sort=False,
@ -220,17 +221,17 @@ class Maintenance(Workflow, ModelSQL, ModelView):
description_activity = fields.Char('Activity') description_activity = fields.Char('Activity')
next_maintenance = fields.Function(fields.Date('Next Maintenance'), 'get_next_maintenance') next_maintenance = fields.Function(fields.Date('Next Maintenance'), 'get_next_maintenance')
temperature_min = fields.Float("Temp Min", required=True) temperature_min = fields.Float("Temp Min")
temperature_max = fields.Float("Temp Max", required=True) temperature_max = fields.Float("Temp Max")
temperature_uom = fields.Many2One('product.uom', 'Temperature UOM',required=True, temperature_uom = fields.Many2One('product.uom', 'Temperature UOM',
domain=[('category', '=', Id('optical_equipment', "uom_cat_temperature"))], domain=[('category', '=', Id('optical_equipment', "uom_cat_temperature"))],
states={'invisible': If(Eval('temperature_min') == None, True), states={'invisible': If(Eval('temperature_min') == None, True),
'readonly' : (Eval('state') == 'finished')}, 'readonly' : (Eval('state') == 'finished')},
depends=['itemperature_min'] depends=['itemperature_min']
) )
moisture_min = fields.Float("Moisture Min", required=True) moisture_min = fields.Float("Moisture Min")
moisture_max = fields.Float("Moisture Max", required=True) moisture_max = fields.Float("Moisture Max")
moisture_uom = fields.Many2One('product.uom', "Moisture UOM", required=True, moisture_uom = fields.Many2One('product.uom', "Moisture UOM",
domain=[('category', '=', Id('optical_equipment', 'uom_cat_relative_humedity'))], domain=[('category', '=', Id('optical_equipment', 'uom_cat_relative_humedity'))],
states={'invisible' : If(Eval('moisture_min') == None, True), states={'invisible' : If(Eval('moisture_min') == None, True),
'readonly': Eval('state') == 'finished'}, 'readonly': Eval('state') == 'finished'},
@ -432,8 +433,12 @@ class Maintenance(Workflow, ModelSQL, ModelView):
y = errors y = errors
if equipment_risk == 'dosB': if equipment_risk == 'dosB':
top = 6 if sum(errors) == 0:
bottom = -6 top = 1.5
bottom = -1.5
else:
top = 2
bottom = -2
else: else:
top = 0.60 top = 0.60
bottom = -0.60 bottom = -0.60
@ -838,6 +843,7 @@ class CreateContractInitial(ModelView, ModelSQL):
'Create Contract Inicial' 'Create Contract Inicial'
__name__ = 'optical_equipment_create.contract' __name__ = 'optical_equipment_create.contract'
currency = fields.Many2One('currency.currency', 'Currency', required=True)
company = fields.Many2One( company = fields.Many2One(
'company.company', "Company", readonly=True, required=True, select=True, 'company.company', "Company", readonly=True, required=True, select=True,
states={ states={
@ -865,7 +871,8 @@ class CreateContractInitial(ModelView, ModelSQL):
datetime.date.min)), datetime.date.min)),
('end_date', '=', None), ('end_date', '=', None),
]) ])
unit_price = Monetary(
"Unit Price", digits=price_digits, currency='currency')
@staticmethod @staticmethod
def default_company(): def default_company():
return Transaction().context.get('company') return Transaction().context.get('company')

66
move.py
View File

@ -11,7 +11,6 @@ class Move(metaclass=PoolMeta):
"Stock Move" "Stock Move"
__name__ = "stock.move" __name__ = "stock.move"
equipment = fields.Many2One('optical_equipment.equipment', "Equipment", equipment = fields.Many2One('optical_equipment.equipment', "Equipment",
domain=[('state', '=', 'registred'), domain=[('state', '=', 'registred'),
('product','=', Eval('product')) ('product','=', Eval('product'))
@ -26,6 +25,7 @@ class Move(metaclass=PoolMeta):
'get_equipment_serial') 'get_equipment_serial')
product_equipment = fields.Function(fields.Boolean("It Equipment"),'get_product_equipment') product_equipment = fields.Function(fields.Boolean("It Equipment"),'get_product_equipment')
@fields.depends('product') @fields.depends('product')
def get_product_equipment(self, product): def get_product_equipment(self, product):
if self.product.equipment: if self.product.equipment:
@ -60,6 +60,13 @@ class ShipmentOut(metaclass=PoolMeta):
"Customer Shipment" "Customer Shipment"
__name__ = 'stock.shipment.out' __name__ = 'stock.shipment.out'
service_maintenance_initial = fields.Boolean('Maintenance Initial', states={'readonly': True})
@classmethod
def __setup__(cls):
super(ShipmentOut, cls).__setup__()
cls._buttons.update({
'maintenance_initial': {'invisible': If(Eval('service_maintenance_initial') == True, True)}})
def get_outgoing_moves(self, name): def get_outgoing_moves(self, name):
moves = [] moves = []
@ -73,6 +80,7 @@ class ShipmentOut(metaclass=PoolMeta):
moves.append(move.id) moves.append(move.id)
return moves return moves
@classmethod @classmethod
def view_attributes(cls): def view_attributes(cls):
return super(ShipmentOut, cls).view_attributes() + [ return super(ShipmentOut, cls).view_attributes() + [
@ -80,15 +88,13 @@ class ShipmentOut(metaclass=PoolMeta):
'invisible': False, 'invisible': False,
}),] }),]
@classmethod @classmethod
@ModelView.button @ModelView.button
@Workflow.transition('done') def maintenance_initial(cls, shipments):
@set_employee('done_by')
def done(cls, shipments):
pool = Pool() pool = Pool()
Move = pool.get('stock.move') MaintenanceService = pool.get('optical_equipment_maintenance.service')
Date = pool.get('ir.date') Maintenance = pool.get('optical_equipment.maintenance')
SaleLine = pool.get('sale.line')
Equipments = pool.get('optical_equipment.equipment') Equipments = pool.get('optical_equipment.equipment')
@ -111,20 +117,42 @@ class ShipmentOut(metaclass=PoolMeta):
else: else:
count+=1 count+=1
Move.delete([ for shipment in shipments:
m for s in shipments for m in s.outgoing_moves sale_origin = shipment.outgoing_moves[0].origin.sale.id
if m.state == 'staging']) saleLine = SaleLine(
type='line',
quantity=1,
unit_price=0,
sale=sale_origin)
saleLine.save()
maintenanceService = MaintenanceService(
sale_date=shipment.outgoing_moves[0].origin.sale.sale_date,
sale_origin=saleLine,
maintenance_type='initial',
propietary=shipment.customer.id,
propietary_address=shipment.delivery_address.id)
maintenanceService.save()
Move.do([m for s in shipments for m in s.outgoing_moves]) serial = False
for company, c_shipments in groupby( for move in shipment.inventory_moves:
shipments, key=lambda s: s.company): if move.product_equipment and move.equipment:
with Transaction().set_context(company=company.id): serial = True
else:
serial = False
today = Date.today() if serial == True:
for move in shipment.inventory_moves:
cls.write([s for s in c_shipments if not s.effective_date], { if move.product_equipment and move.equipment:
'effective_date': today, maintenance = Maintenance(
}) service_maintenance=maintenanceService.id,
maintenance_type='initial',
propietary=shipment.customer.id,
propietary_address=shipment.delivery_address.id,
equipment=move.equipment.id)
maintenance.save()
shipment.service_maintenance_initial = True
else:
raise UserError(str('Por favor Primero debe Asignar un serial a todos los Equipos.'))
def _get_inventory_move(self, move): def _get_inventory_move(self, move):
'Return inventory move for the outgoing move if necessary' 'Return inventory move for the outgoing move if necessary'

View File

@ -12,6 +12,11 @@ this repository contains the full copyright notices and license terms. -->
<field name="inherit" ref="stock.move_view_form"/> <field name="inherit" ref="stock.move_view_form"/>
<field name="name">move_form</field> <field name="name">move_form</field>
</record> </record>
<record model="ir.model.button" id="maintenance_initial_button">
<field name="name">maintenance_initial</field>
<field name="string">Maintenance Initial</field>
<field name="model" search="[('model', '=', 'stock.shipment.out')]"/>
</record>
<record model="ir.action.report" id="report_shipment_out_picking_list1"> <record model="ir.action.report" id="report_shipment_out_picking_list1">
<field name="name">Acta Entrega</field> <field name="name">Acta Entrega</field>
<field name="model">stock.shipment.out</field> <field name="model">stock.shipment.out</field>

View File

@ -31,5 +31,4 @@ xml:
message.xml message.xml
diary.xml diary.xml
maintenance.xml maintenance.xml
shipment.xml