fix force draft and modify assing lot

This commit is contained in:
wilsongomez 2022-09-29 17:56:45 -05:00
parent 0cc7aa0718
commit e2b1568aec
4 changed files with 73 additions and 77 deletions

10
message.xml Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tryton>
<data grouped="1">
<record model="ir.message" id="msg_missing_quantity_lot">
<field name="text">Missing quantity lot for product "%(product)s"</field>
</record>
</data>
</tryton>

View File

@ -14,6 +14,8 @@ from trytond.pyson import Eval, If, And, DateTime , Date, Bool, Or
from trytond.report import Report
from trytond.wizard import Wizard, StateReport, StateView, Button, StateTransition
from trytond.transaction import Transaction
from trytond.exceptions import UserError
from trytond.i18n import gettext
class Production(metaclass=PoolMeta):
@ -92,8 +94,9 @@ class Production(metaclass=PoolMeta):
Lot = pool.get('stock.lot')
MovePhyto = pool.get('stock.lot.phyto.move')
for production in productions:
if production.state == 'assigned':
continue
for input in production.inputs:
print(input.product.name)
if input.product.farming:
lots = Lot.search([
('product', '=', input.product.id),
@ -126,7 +129,9 @@ class Production(metaclass=PoolMeta):
lot.save()
else:
break
if required_quantity > 0:
raise UserError(
gettext('farming.msg_missing_quantity_lot', product=input.product.name))
@classmethod
def draft(cls, productions):
@ -149,13 +154,25 @@ class Production(metaclass=PoolMeta):
def assign(cls, productions):
super(Production, cls).assign(productions)
for pd in productions:
cls.assign_lot([pd])
if pd.subproductions:
cls.assign(pd.subproductions)
#cls.assign_lot([pd])
#cls.assign_lot(pd.subproductions)
cls.run(pd.subproductions)
# cls.run(pd.subproductions)
@classmethod
def run(cls, productions):
super(Production, cls).run(productions)
for pd in productions:
if pd.subproductions:
cls.run(pd.subproductions)
@classmethod
def done(cls, productions):
super(Production, cls).done(productions)
for pd in productions:
cls.assign_lot([pd])
if pd.subproductions:
cls.done(pd.subproductions)
@classmethod
def copy(cls, records, default=None):
pass
@ -617,92 +634,60 @@ class ProductionForceDraft(Wizard):
force_draft = StateTransition()
def _reset_data(self, prod, delete=None):
Production = Pool().get('production')
cursor = Transaction().connection.cursor()
pool = Pool()
Production = pool.get('production')
Move_Phyto = pool.get('stock.lot.phyto.move')
Lot = pool.get('stock.lot')
stock_move = Table('stock_move')
move_phyto_table = Table('stock_lot_phyto_move')
Move_Phyto = Pool().get('stock.lot.phyto.move')
Lot = Pool().get('stock.lot')
lot = Pool().get('stock.lot').__table__()
moves_phytos_update = []
cursor = Transaction().connection.cursor()
lots_to_update = []
if not delete:
print('entro en el if')
for rec in prod.outputs:
outputs_to_delete = [out.id for out in prod.outputs]
if outputs_to_delete:
cursor.execute(*stock_move.delete(
where=stock_move.id == rec.id)
)
where=stock_move.id.in_(outputs_to_delete)))
origin_inputs = []
inputs_to_update = []
for rec in prod.inputs:
origin = str(rec)
query = move_phyto_table.join(lot, condition=move_phyto_table.lot== lot.id
).select(lot.id, where=move_phyto_table.origin==origin)
print(query)
print(origin)
cursor.execute(*query)
result = cursor.fetchall()
print(result)
if result:
lots_to_update.extend(result[0])
cursor.execute(*move_phyto_table.delete(
where=move_phyto_table.origin == str(rec))
)
print(rec.id, 'movimiento phyto')
origin_inputs.append(str(rec))
inputs_to_update.append(rec.id)
if inputs_to_update:
cursor.execute(*stock_move.update(
columns=[stock_move.state],
values=['cancelled'],
where=stock_move.id == rec.id)
where=stock_move.id.in_(inputs_to_update))
)
print(rec.id, 'id movimiento')
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)
prod.state = 'draft'
prod.save()
else:
print('entro en el else')
origin_inputs = []
inputs_to_delete = []
for rec in prod.inputs:
origin = str(rec)
query = move_phyto_table.join(lot, condition=move_phyto_table.lot== lot.id
).select(lot.id, where=move_phyto_table.origin==origin)
print(query)
print(origin)
cursor.execute(*query)
result = cursor.fetchall()
if result:
lots_to_update.extend(result[0])
cursor.execute(*move_phyto_table.delete(
where=move_phyto_table.origin == str(rec))
)
origin_inputs.append(str(rec))
inputs_to_update.append(rec.id)
print(rec.id, 'movimiento phyto')
cursor.execute(*stock_move.update(
columns=[stock_move.state],
values=['cancelled'],
where=stock_move.id == rec.id)
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_delete = [r.id for r in prod.outputs] + inputs_to_delete
if moves_to_delete:
cursor.execute(*stock_move.delete(
where=stock_move.id.in_(moves_to_delete) )
)
print(rec.id, 'id movimiento')
prod.state = 'draft'
prod.save()
for rec in prod.outputs + prod.inputs:
origin = str(rec)
query = move_phyto_table.join(lot, condition=move_phyto_table.lot== lot.id
).select(lot.id, where=move_phyto_table.origin==origin)
print(query)
print(origin)
cursor.execute(*query)
result = cursor.fetchall()
if result:
lots_to_update.extend(result[0])
cursor.execute(*move_phyto_table.delete(
where=move_phyto_table.origin == str(rec))
)
cursor.execute(*stock_move.delete(
where=stock_move.id == rec.id)
)
Production.delete([prod])
if lots_to_update:
lots = Lot.search([('id', 'in', list(set(lots_to_update)))])
move_phyto = Move_Phyto.search([('id', 'in', list(set(moves_phytos_update)))])
Lot.recompute_balance(lots)
Lot.recompute_balance(list(set(lots_to_update)))
def transition_force_draft(self):
id_ = Transaction().context['active_id']

View File

@ -88,10 +88,10 @@ class PythoMove(ModelSQL, ModelView):
@classmethod
def delete(cls, records):
StockLot = Pool().get('stock.lot')
for rec in records:
stocklot = StockLot.search(['id', '=', rec.lot.id])
stock_lots = set(r.lot.id for r in records)
lots = StockLot.search([('id', 'in', list(stock_lots))])
StockLot.recompute_balance(lots)
super(PythoMove, cls).delete(records)
StockLot.recompute_balance(stocklot)
class StockMove(metaclass=PoolMeta):

View File

@ -29,3 +29,4 @@ xml:
exportation.xml
work.xml
genetics.xml
message.xml