trytonpsk-farming/production.py

672 lines
25 KiB
Python
Raw Normal View History

2020-04-16 15:04:10 +02:00
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
2021-12-07 07:06:39 +01:00
import copy
2022-07-23 15:28:46 +02:00
from datetime import timedelta, date, datetime
2022-01-20 21:43:37 +01:00
from sql import Table
2023-01-14 16:15:34 +01:00
from trytond.model import fields, ModelView, ModelSQL
2021-11-02 18:25:11 +01:00
from trytond.pool import PoolMeta, Pool
2023-01-14 16:15:34 +01:00
from trytond.pyson import Eval
2021-11-19 05:30:55 +01:00
from trytond.report import Report
2023-01-14 16:15:34 +01:00
from trytond.wizard import (
Wizard, StateReport, StateView, Button, StateTransition)
2021-11-19 05:30:55 +01:00
from trytond.transaction import Transaction
2022-09-30 00:56:45 +02:00
from trytond.exceptions import UserError
from trytond.i18n import gettext
2020-04-16 15:04:10 +02:00
2021-11-07 19:37:51 +01:00
class Production(metaclass=PoolMeta):
__name__ = 'production'
STATES = {
2022-01-21 15:35:25 +01:00
'readonly': Eval('state') == 'done',
2021-11-07 19:37:51 +01:00
}
2021-11-18 05:47:52 +01:00
pack = fields.Many2One('production', 'Pack')
subproductions = fields.One2Many('production', 'pack', 'Sub-Productions')
move_phytos = fields.One2Many('stock.lot.phyto.move', 'pack', 'Move Phyto')
2022-04-12 01:19:12 +02:00
tasks = fields.One2Many('production.task', 'production', 'Tasks')
2021-11-07 19:37:51 +01:00
customer = fields.Many2One('party.party', 'Customer', states=STATES)
delivery_date = fields.Date('Delivery Date', states=STATES)
2021-11-19 05:30:55 +01:00
factor_packing = fields.Float('Factor Packing')
units = fields.Function(fields.Float('Units', digits=(16, 2)), 'get_units')
notes = fields.Text('Notes')
2021-12-01 23:43:11 +01:00
primary = fields.Boolean('Primary')
2022-01-19 17:14:59 +01:00
@classmethod
def __setup__(cls):
super(Production, cls).__setup__()
2022-01-19 18:46:54 +01:00
cls.state_string = cls.state.translated('state')
2021-11-18 05:47:52 +01:00
@classmethod
def _get_origin(cls):
return super()._get_origin() | {'sale.line'}
2021-11-07 19:37:51 +01:00
def on_change_with_unit_qty(self, name=None):
if self.quantity and self.uom:
res = self.quantity * self.uom.rate
return res
2021-11-19 05:30:55 +01:00
def get_units(self, name=None):
res = []
for line in self.inputs:
if line.product.farming:
res.append(line.quantity * line.uom.factor)
2022-06-02 22:05:53 +02:00
for p in self.subproductions:
res.append(p.units)
return sum(res)
2021-11-19 05:30:55 +01:00
2021-11-07 19:37:51 +01:00
def get_boxes(self, name=None):
if self.packing_qty and self.packing_uom:
return self.packing_qty * self.packing_uom.factor
2021-12-01 16:08:33 +01:00
@classmethod
def assign_lot(cls, productions):
pool = Pool()
Lot = pool.get('stock.lot')
MovePhyto = pool.get('stock.lot.phyto.move')
for production in productions:
delivery_date = production.delivery_date
2022-09-30 00:56:45 +02:00
if production.state == 'assigned':
continue
for input in production.inputs:
2023-01-14 16:15:34 +01:00
has_origin = MovePhyto.search_read(
[('origin', '=', str(input))], limit=1
)
2022-10-08 00:56:53 +02:00
if input.product.farming and len(has_origin) <= 0:
lots = Lot.search([
('product', '=', input.product.id),
('balance', '>', 0)
], order=[('create_date', 'ASC')])
2023-01-14 16:15:34 +01:00
required_quantity = input.quantity
2021-12-01 22:06:43 +01:00
for lot in lots:
2023-01-14 16:15:34 +01:00
if required_quantity > 0:
move_in = 0
lot_balance = lot.balance
if required_quantity >= lot_balance:
lot.balance_export += lot_balance
lot.balance = 0
required_quantity -= lot_balance
move_in = lot_balance
elif required_quantity < lot_balance:
lot.balance -= required_quantity
lot.balance_export += required_quantity
move_in = required_quantity
required_quantity = 0
move_phyto = MovePhyto(
2023-01-14 16:15:34 +01:00
lot=lot.id,
origin=(input),
date_move=delivery_date,
move_in=move_in,
move_out=0
)
move_phyto.save()
lot.save()
2021-12-01 22:06:43 +01:00
else:
break
2022-09-30 00:56:45 +02:00
if required_quantity > 0:
raise UserError(
2023-01-14 16:15:34 +01:00
gettext(
'farming.msg_missing_quantity_lot',
product=input.product.name))
2021-12-01 22:06:43 +01:00
@classmethod
def draft(cls, productions):
for pd in productions:
if pd.subproductions:
cls.draft(pd.subproductions)
super(Production, cls).draft(productions)
2021-12-01 16:08:33 +01:00
@classmethod
def wait(cls, productions):
for pd in productions:
2022-01-04 07:45:33 +01:00
for move in pd.inputs:
move.origin = str(pd)
move.save()
2021-12-01 16:08:33 +01:00
if pd.subproductions:
2021-12-01 22:06:43 +01:00
cls.wait(pd.subproductions)
super(Production, cls).wait(productions)
@classmethod
def assign(cls, productions):
super(Production, cls).assign(productions)
2021-12-01 22:06:43 +01:00
for pd in productions:
if pd.subproductions:
cls.assign(pd.subproductions)
2022-09-30 00:56:45 +02:00
# cls.run(pd.subproductions)
@classmethod
def run(cls, productions):
super(Production, cls).run(productions)
for pd in productions:
if pd.subproductions:
2023-01-14 16:15:34 +01:00
cls.run(pd.subproductions)
2022-09-30 00:56:45 +02:00
@classmethod
def done(cls, productions):
super(Production, cls).done(productions)
for pd in productions:
cls.assign_lot([pd])
if pd.subproductions:
2023-01-14 16:15:34 +01:00
cls.done(pd.subproductions)
2022-09-30 00:56:45 +02:00
2022-01-18 01:41:53 +01:00
@classmethod
def copy(cls, records, default=None):
pass
2021-11-07 19:37:51 +01:00
2022-04-08 09:07:29 +02:00
class ProductionTask(ModelView, ModelSQL):
2022-04-08 09:22:09 +02:00
"Production Task"
2022-04-08 09:07:29 +02:00
__name__ = 'production.task'
STATES = {
'readonly': Eval('state') == 'finished',
}
operation = fields.Many2One('production.routing.operation', 'Operation',
required=True, states=STATES)
2022-04-08 09:42:13 +02:00
effective_date = fields.Date('Effective Date ', states=STATES,
2022-04-08 09:07:29 +02:00
required=True)
employee = fields.Many2One('company.employee', 'Employee',
states=STATES)
quantity = fields.Float('Quantity', states=STATES, required=True)
2022-04-12 01:27:05 +02:00
goal = fields.Integer('Goal', states={'readonly': True},
help="In minutes")
2022-08-12 15:52:20 +02:00
start_time = fields.DateTime('Start Time')
2022-04-08 09:20:25 +02:00
end_time = fields.DateTime('End Time', states=STATES)
2022-04-12 01:19:12 +02:00
planned_end_time = fields.Function(fields.DateTime('Planned End Time'),
'get_planned_end_time')
total_time = fields.Integer('Total Time', states={'readonly': True},
help="In minutes")
2022-04-08 09:30:31 +02:00
performance = fields.Function(fields.Float('Performance', digits=(4, 2)),
2022-04-08 09:07:29 +02:00
'get_performance')
2022-04-12 01:19:12 +02:00
production = fields.Many2One('production', 'Production', states=STATES)
2023-01-14 16:15:34 +01:00
customer = fields.Many2One('party.party', 'Customer')
reference = fields.Many2One('product.product', 'Product',
domain=[('type', '=', 'goods')])
units = fields.Integer('Units')
2022-08-26 23:11:05 +02:00
uom = fields.Many2One('product.uom', 'Uom')
factor = fields.Integer('Factor')
work_center = fields.Many2One('production.work.center', 'Work Center')
2022-04-12 21:34:55 +02:00
notes = fields.Char('Notes', states=STATES)
2022-04-08 09:07:29 +02:00
state = fields.Selection([
('draft', 'Draft'),
('processing', 'Processing'),
('finished', 'Finished'),
], 'State', select=True)
2022-04-19 22:16:52 +02:00
@classmethod
def __setup__(cls):
super(ProductionTask, cls).__setup__()
cls._buttons.update({
2023-01-14 16:15:34 +01:00
'duplicate_wizard': {},
'finishButton': {}
})
2022-08-17 18:57:24 +02:00
@classmethod
@ModelView.button
def finishButton(cls, records):
for rec in records:
rec.end_time = datetime.now()
rec.state = 'finished'
2022-08-19 00:01:10 +02:00
rec.total_time = int((rec.end_time - rec.start_time).seconds / 60)
2022-08-17 18:57:24 +02:00
rec.save()
2023-01-14 16:15:34 +01:00
2022-04-08 09:30:31 +02:00
@staticmethod
def default_state():
return 'draft'
2022-07-18 23:05:28 +02:00
@staticmethod
def default_effective_date():
return date.today()
2022-08-12 15:52:20 +02:00
@staticmethod
def default_start_time():
return datetime.now()
@staticmethod
2022-08-19 00:01:10 +02:00
def default_end_time():
2022-08-12 15:52:20 +02:00
return datetime.now()
2022-04-19 22:16:52 +02:00
@classmethod
2022-04-19 22:40:15 +02:00
@ModelView.button_action('farming.act_wizard_production_duplicate_task')
2022-04-19 22:16:52 +02:00
def duplicate_wizard(cls, records):
pass
2023-01-14 16:15:34 +01:00
2022-04-12 01:19:12 +02:00
def get_planned_end_time(self, name):
if self.start_time and self.goal:
return self.start_time + timedelta(minutes=self.goal)
@fields.depends('production')
2023-01-14 16:15:34 +01:00
def on_change_with_customer(self, name=None):
2022-08-19 00:01:10 +02:00
if self.production:
return self.production.customer.id
2023-01-14 16:15:34 +01:00
@fields.depends('production')
2023-01-14 16:15:34 +01:00
def on_change_with_reference(self, name=None):
2022-08-19 00:01:10 +02:00
if self.production:
return self.production.product.id
2022-08-19 00:01:10 +02:00
2022-04-12 01:19:12 +02:00
@fields.depends('operation', 'quantity')
def on_change_with_goal(self, name=None):
if self.operation and self.quantity and self.operation.productivity:
2023-01-14 16:15:34 +01:00
return int((self.operation.productivity / 60) * self.quantity)
2022-04-12 01:19:12 +02:00
2022-04-08 09:07:29 +02:00
@fields.depends('start_time', 'end_time')
2022-04-08 09:30:31 +02:00
def on_change_with_total_time(self, name=None):
2022-04-08 09:07:29 +02:00
if self.start_time and self.end_time:
2022-04-08 09:42:13 +02:00
return int((self.end_time - self.start_time).seconds / 60)
2022-04-08 09:07:29 +02:00
def get_performance(self, name=None):
if self.total_time and self.goal:
2022-04-08 09:55:05 +02:00
return round(self.goal / self.total_time, 2)
2022-04-08 09:07:29 +02:00
2021-11-19 05:30:55 +01:00
class ProductionSummaryStart(ModelView):
'Production Report Start'
__name__ = 'production.summary.start'
company = fields.Many2One('company.company', 'Company', required=True)
2022-01-26 19:00:59 +01:00
start_date = fields.Date("Start Date", required=True)
end_date = fields.Date("End Date", required=True)
2021-11-19 05:30:55 +01:00
@staticmethod
def default_company():
return Transaction().context.get('company')
@staticmethod
def default_start_date():
return date.today()
@staticmethod
def default_end_date():
return date.today()
2021-11-19 05:30:55 +01:00
class ProductionSummary(Wizard):
'Purchase Analytic Report'
__name__ = 'production.summary'
2023-01-14 16:15:34 +01:00
start = StateView(
'production.summary.start',
2021-11-19 05:30:55 +01:00
'farming.production_summary_start_view_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Print', 'print_', 'tryton-ok', default=True),
])
print_ = StateReport('production.summary_report')
def do_print_(self, action):
data = {
'company': self.start.company.id,
2022-01-26 19:00:59 +01:00
'start_date': self.start.start_date,
'end_date': self.start.end_date,
2021-11-19 05:30:55 +01:00
}
return action, data
def transition_print_(self):
return 'end'
class ProductionSummaryReport(Report):
__name__ = 'production.summary_report'
@classmethod
def get_context(cls, records, header, data):
report_context = super().get_context(records, header, data)
pool = Pool()
Company = pool.get('company.company')
Production = pool.get('production')
Product = pool.get('product.product')
2021-11-19 05:30:55 +01:00
records = Production.search([
('company', '=', data['company']),
('pack', '=', None),
2022-01-26 19:00:59 +01:00
('planned_date', '>=', data['start_date']),
('planned_date', '<=', data['end_date']),
2021-11-19 05:30:55 +01:00
], order=[('id', 'ASC')])
2021-11-22 17:59:01 +01:00
inputs = {}
2023-01-14 16:15:34 +01:00
types = {'solidos': {}, 'bouquets': {}}
styles = []
styles_append = styles.append
products = []
products_append = products.append
locations = set()
2021-11-22 17:59:01 +01:00
for rec in records:
2022-06-15 16:10:45 +02:00
state = rec.state
rec_id = rec.id
types['solidos'][rec_id] = rec
locations.add(rec.warehouse.storage_location.id)
2021-11-22 17:59:01 +01:00
for inp in rec.inputs:
_inputs = [inp]
if inp.product.template.producible and inp.production:
_inputs.extend(inp.production.inputs)
types['bouquets'][rec_id] = rec
2021-11-22 17:59:01 +01:00
for _inp in _inputs:
if _inp.style:
styles_append(_inp)
2021-11-22 17:59:01 +01:00
product = _inp.product
product_id = str(product.id)
products_append(product_id)
2023-01-14 16:15:34 +01:00
cat = None
if product.categories:
cat = product.categories[0]
cat_id = str(cat.id if cat else 'none')
cat_name = cat.name if cat else 'none'
key = cat_id + '_' + product_id
qty_pending = 0
2022-06-15 16:10:45 +02:00
if state != 'done':
2023-01-14 16:15:34 +01:00
qty_pending = _inp.quantity
if key not in inputs.keys():
inputs[key] = {
'id': product_id,
2022-08-26 23:11:05 +02:00
'category': cat_name,
2021-11-22 17:59:01 +01:00
'product': product.rec_name,
'quantity': _inp.quantity,
'uom': product.default_uom.name,
2022-06-14 23:16:45 +02:00
'solidos': 0,
2023-01-16 16:37:38 +01:00
'quantity_pending': qty_pending
2021-11-22 17:59:01 +01:00
}
else:
qty = inputs[key]['quantity']
2023-01-16 16:37:38 +01:00
pend = inputs[key]['quantity_pending']
inputs[key]['quantity'] = qty + _inp.quantity
2023-01-16 16:37:38 +01:00
inputs[key]['quantity_pending'] = pend + qty_pending
2022-07-18 23:04:26 +02:00
with Transaction().set_context({'locations': list(locations)}):
2023-01-14 16:15:34 +01:00
products = Product.search_read(
[('id', 'in', products)],
fields_names=['quantity'])
products = {str(p['id']): p for p in products}
totals = {
'box': {
'solidos': 0,
'bouquets': 0,
'process': 0,
'done': 0
},
'stem': {
'solidos': 0,
'bouquets': 0,
'process': 0,
'done': 0}
}
2022-06-02 17:00:19 +02:00
_solidos = []
for s in list(types['solidos'].keys()):
if s in types['bouquets'].keys():
del types['solidos'][s]
else:
quantity = types['solidos'][s].quantity
units = types['solidos'][s].units
state = types['solidos'][s].state
2022-06-02 17:00:19 +02:00
flag = 0
2022-07-18 23:04:26 +02:00
for _input in types['solidos'][s].inputs:
2022-06-02 17:08:38 +02:00
if _input.uom.symbol == 'STEM':
2022-06-15 16:10:45 +02:00
if state != 'done':
2023-01-14 16:15:34 +01:00
cat_id = str(
_input.product.categories[0].id) if _input.product.categories else 'none'
key = cat_id + '_' + str(_input.product.id)
2022-06-15 16:10:45 +02:00
inputs[key]['solidos'] += _input.quantity
2022-06-02 17:00:19 +02:00
flag += 1
if flag == 1:
2023-01-14 16:15:34 +01:00
_solidos.append({
'input': _input,
'pcc': _input.production_input
})
2022-06-02 17:00:19 +02:00
else:
_solidos.append({'input': _input, 'pcc': None})
state = 'done' if state == 'done' else 'process'
2023-01-14 16:15:34 +01:00
totals = cls.get_values(
totals, 'solidos', state, units, quantity)
2023-01-14 16:15:34 +01:00
_bouquets = []
for b in types['bouquets'].values():
flag = 0
2022-07-18 23:04:26 +02:00
for _input in b.inputs:
if _input.uom.symbol not in ['u', 'STEM']:
flag += 1
if flag == 1:
2023-01-14 16:15:34 +01:00
pcc = _input.production_input
2022-07-18 23:04:26 +02:00
_bouquets.append({'input': _input, 'pcc': pcc})
quantity = pcc.quantity
units = pcc.units
state = pcc.state
state = 'done' if state == 'done' else 'process'
2023-01-14 16:15:34 +01:00
totals = cls.get_values(
totals, 'bouquets', state, units, quantity)
else:
2023-01-14 16:15:34 +01:00
_bouquets.append({
'input': _input,
'pcc': None,
'factor_packing': _input.quantity/_input.production_input.quantity
})
2021-11-19 05:30:55 +01:00
report_context['records'] = records
report_context['inputs'] = dict(sorted(inputs.items())).values()
2022-06-02 17:00:19 +02:00
report_context['solidos'] = _solidos
report_context['bouquets'] = _bouquets
report_context['styles'] = styles
report_context['totals'] = totals
report_context['products'] = products
2022-01-26 19:00:59 +01:00
report_context['start_date'] = data['start_date']
report_context['end_date'] = data['end_date']
2021-11-19 05:30:55 +01:00
report_context['company'] = Company(data['company'])
return report_context
2021-12-07 07:06:39 +01:00
@classmethod
def get_values(cls, totals, type, state, units, quantity):
totals['stem'][type] += units
totals['stem'][state] += units
totals['box'][type] += quantity
totals['box'][state] += quantity
return totals
2021-12-07 07:06:39 +01:00
2023-01-14 16:15:34 +01:00
2021-12-07 07:06:39 +01:00
class MaterialsForecastStart(ModelView):
'Materials Forecast Start'
__name__ = 'production.materials_forecast.start'
company = fields.Many2One('company.company', 'Company', required=True)
date_ = fields.Date("Date", required=True)
2022-01-05 17:33:56 +01:00
storage = fields.Many2One('stock.location', 'Location', required=True,
domain=[('type', '=', 'storage')])
2021-12-07 07:06:39 +01:00
@staticmethod
def default_company():
return Transaction().context.get('company')
class MaterialsForecast(Wizard):
'Materials Forecast'
__name__ = 'production.materials_forecast'
2023-01-14 16:15:34 +01:00
start = StateView(
'production.materials_forecast.start',
2021-12-07 07:06:39 +01:00
'farming.production_materials_forecast_start_view_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Print', 'print_', 'tryton-ok', default=True),
])
print_ = StateReport('production.materials_forecast.report')
def do_print_(self, action):
data = {
'company': self.start.company.id,
'date': self.start.date_,
2022-01-05 17:33:56 +01:00
'storage': self.start.storage.id,
2021-12-07 07:06:39 +01:00
}
return action, data
def transition_print_(self):
return 'end'
class MaterialsForecastReport(Report):
'Materials Forecast Report'
__name__ = 'production.materials_forecast.report'
@classmethod
def get_context(cls, records, header, data):
report_context = super().get_context(records, header, data)
pool = Pool()
Company = pool.get('company.company')
Production = pool.get('production')
Purchase = pool.get('purchase.purchase')
Product = pool.get('product.product')
default_dates = {}
for i in range(6):
d = data['date'] + timedelta(days=i)
default_dates[str(d)] = {
'stock': 0,
'in': 0,
'pcc': 0,
'balance': 0,
}
report_context['date' + str(1+i)] = str(d)
last_date = data['date'] + timedelta(days=5)
productions = Production.search([
('company', '=', data['company']),
('planned_date', '>=', data['date']),
('planned_date', '<=', last_date),
], order=[('planned_date', 'ASC')])
products = {}
for pcc in productions:
for inp in pcc.inputs:
if not inp.product.template.purchasable:
continue
if inp.product not in products.keys():
products[inp.product] = copy.deepcopy(default_dates)
products[inp.product]['name'] = inp.product.rec_name
products[inp.product]['uom'] = inp.product.template.default_uom.symbol
products[inp.product][str(pcc.planned_date)]['pcc'] += inp.quantity
purchases = Purchase.search([
('company', '=', data['company']),
2022-01-05 17:38:10 +01:00
('delivery_date', '>=', data['date']),
('delivery_date', '<=', last_date),
2021-12-07 07:06:39 +01:00
('state', 'in', ['quotation', 'processing', 'done', 'confirmed']),
], order=[('delivery_date', 'ASC')])
for pch in purchases:
for line in pch.lines:
if line.product not in products.keys():
products[line.product] = copy.deepcopy(default_dates)
products[line.product]['name'] = line.product.rec_name
products[line.product]['uom'] = line.product.template.default_uom.symbol
products[line.product][str(pch.delivery_date)]['in'] += line.quantity
2022-01-04 16:18:46 +01:00
date_ = data['date'] - timedelta(days=1)
2021-12-07 07:06:39 +01:00
ctx = {
2022-01-05 17:33:56 +01:00
'locations': [data['storage']],
2022-01-04 16:18:46 +01:00
'stock_date_end': date_,
2021-12-07 07:06:39 +01:00
}
2022-01-04 17:20:57 +01:00
2021-12-07 07:06:39 +01:00
def get_balance(qty, product_date):
res = qty + product_date['in'] - product_date['pcc']
return res
# Search stock of products
product_ids = [pd.id for pd in products.keys()]
with Transaction().set_context(ctx):
_products = Product.search([
('id', 'in', product_ids),
('template.purchasable', '=', True),
2022-01-04 17:01:03 +01:00
], order=[('template.name', 'ASC')]
2021-12-07 07:06:39 +01:00
)
for pt in _products:
stock = pt.quantity
for dt in default_dates.keys():
product_date = products[pt][str(dt)]
product_date['stock'] = stock
value = get_balance(stock, product_date)
product_date['balance'] = value
stock = value
report_context['records'] = products.values()
report_context['date'] = data['date']
report_context['company'] = Company(data['company'])
return report_context
2022-01-20 21:43:37 +01:00
class ProductionForceDraft(Wizard):
'Production Force Draft'
__name__ = 'production.force_draft'
start_state = 'force_draft'
force_draft = StateTransition()
2022-01-22 21:47:19 +01:00
def _reset_data(self, prod, delete=None):
2022-09-30 00:56:45 +02:00
pool = Pool()
Move_Phyto = pool.get('stock.lot.phyto.move')
Lot = pool.get('stock.lot')
2022-01-20 21:43:37 +01:00
stock_move = Table('stock_move')
2022-09-30 00:56:45 +02:00
cursor = Transaction().connection.cursor()
lots_to_update = []
2022-01-22 21:47:19 +01:00
if not delete:
outputs_to_update = [out.id for out in prod.outputs]
2022-09-30 00:56:45 +02:00
origin_inputs = []
inputs_to_update = []
2022-01-20 21:43:37 +01:00
for rec in prod.inputs:
2022-09-30 00:56:45 +02:00
origin_inputs.append(str(rec))
inputs_to_update.append(rec.id)
moves_to_update = outputs_to_update + inputs_to_update
if moves_to_update:
2022-09-24 23:10:48 +02:00
cursor.execute(*stock_move.update(
columns=[stock_move.state],
values=['draft'],
where=stock_move.id.in_(moves_to_update))
2022-09-24 23:10:48 +02:00
)
2022-09-30 00:56:45 +02:00
move_phytos = Move_Phyto.search([('origin', 'in', origin_inputs)])
lots_to_update.extend(set(m.lot for m in move_phytos))
Move_Phyto.delete(move_phytos)
2022-09-24 23:10:48 +02:00
prod.state = 'draft'
prod.save()
2022-01-22 21:47:19 +01:00
else:
2022-09-30 00:56:45 +02:00
origin_inputs = []
inputs_to_delete = []
for rec in prod.inputs:
2022-09-30 00:56:45 +02:00
origin_inputs.append(str(rec))
inputs_to_update.append(rec.id)
2023-01-14 16:15:34 +01:00
2022-09-30 00:56:45 +02:00
move_phytos = Move_Phyto.search([('origin', 'in', origin_inputs)])
lots_to_update.extend(set(m.lot for m in move_phytos))
Move_Phyto.delete(move_phytos)
moves_to_update = [r.id for r in prod.outputs] + inputs_to_delete
if moves_to_update:
cursor.execute(*stock_move.update(
columns=[stock_move.state],
values=['draft'],
where=stock_move.id.in_(moves_to_update))
2022-09-24 23:10:48 +02:00
)
2022-09-30 00:56:45 +02:00
2022-09-24 23:10:48 +02:00
prod.state = 'draft'
prod.save()
2022-09-30 00:56:45 +02:00
if lots_to_update:
2022-09-30 00:56:45 +02:00
Lot.recompute_balance(list(set(lots_to_update)))
2022-01-22 21:47:19 +01:00
def transition_force_draft(self):
id_ = Transaction().context['active_id']
Production = Pool().get('production')
if id_:
prod = Production(id_)
self._reset_data(prod)
for pr in prod.subproductions:
self._reset_data(pr, True)
2022-01-20 21:43:37 +01:00
return 'end'
2022-04-12 01:19:12 +02:00
class Operation(metaclass=PoolMeta):
__name__ = 'production.routing.operation'
2022-04-19 22:02:26 +02:00
productivity = fields.Float('Productivity', digits=(6, 2),
2022-04-12 01:19:12 +02:00
help='Seconds neccesary for make one unit')
2022-04-19 22:02:26 +02:00
class DuplicateTask(Wizard):
'Duplicate Task'
__name__ = 'production.task.duplicate'
start_state = 'duplicate_lines'
duplicate_lines = StateTransition()
def transition_duplicate_lines(self):
active_id = Transaction().context.get('active_id')
Task = Pool().get('production.task')
task = Task(active_id)
2022-04-19 22:41:32 +02:00
default = {'production': task.production}
2022-04-19 22:02:26 +02:00
Task.copy([task], default=default)
return 'end'