Remove datetime.date.today() from stock and use ir.date.today
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
from trytond.model import ModelView, ModelSQL, fields
|
||||
from trytond.backend import TableHandler
|
||||
from decimal import Decimal
|
||||
import datetime
|
||||
|
||||
STATES = {
|
||||
'readonly': "(state in ('cancel', 'done'))",
|
||||
@@ -418,6 +417,7 @@ class Move(ModelSQL, ModelView):
|
||||
location_obj = self.pool.get('stock.location')
|
||||
currency_obj = self.pool.get('currency.currency')
|
||||
company_obj = self.pool.get('company.company')
|
||||
date_obj = self.pool.get('ir.date')
|
||||
|
||||
if context is None:
|
||||
context = {}
|
||||
@@ -430,7 +430,7 @@ class Move(ModelSQL, ModelView):
|
||||
ctx = context and context.copy() or {}
|
||||
ctx['locations'] = location_obj.search(
|
||||
cursor, user, [('type', '=', 'storage')], context=context)
|
||||
ctx['stock_date_end'] = datetime.date.today()
|
||||
ctx['stock_date_end'] = date_obj.today(cursor, user, context=context)
|
||||
product = product_obj.browse(cursor, user, product_id, context=ctx)
|
||||
qty = uom_obj.compute_qty(
|
||||
cursor, user, uom, quantity, product.default_uom, context=context)
|
||||
@@ -460,12 +460,14 @@ class Move(ModelSQL, ModelView):
|
||||
def create(self, cursor, user, vals, context=None):
|
||||
location_obj = self.pool.get('stock.location')
|
||||
product_obj = self.pool.get('product.product')
|
||||
date_obj = self.pool.get('ir.date')
|
||||
|
||||
vals = vals.copy()
|
||||
|
||||
if vals.get('state') == 'done':
|
||||
if not vals.get('effective_date'):
|
||||
vals['effective_date'] = datetime.date.today()
|
||||
vals['effective_date'] = date_obj.today(cursor, user,
|
||||
context=context)
|
||||
from_location = location_obj.browse(cursor, user,
|
||||
vals['from_location'], context=context)
|
||||
to_location = location_obj.browse(cursor, user,
|
||||
@@ -492,10 +494,13 @@ class Move(ModelSQL, ModelView):
|
||||
|
||||
elif vals.get('state') == 'assigned':
|
||||
if not vals.get('effective_date'):
|
||||
vals['effective_date'] = datetime.date.today()
|
||||
vals['effective_date'] = date_obj.today(cursor, user,
|
||||
context=context)
|
||||
return super(Move, self).create(cursor, user, vals, context=context)
|
||||
|
||||
def write(self, cursor, user, ids, vals, context=None):
|
||||
date_obj = self.pool.get('ir.date')
|
||||
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
@@ -529,12 +534,14 @@ class Move(ModelSQL, ModelView):
|
||||
if move.state in ('cancel', 'done'):
|
||||
self.raise_user_error(cursor, 'set_state_assigned',
|
||||
context=context)
|
||||
vals['effective_date'] = datetime.date.today()
|
||||
vals['effective_date'] = date_obj.today(cursor, user,
|
||||
context=context)
|
||||
elif vals['state'] == 'done':
|
||||
if move.state in ('cancel'):
|
||||
self.raise_user_error(cursor, 'set_state_done',
|
||||
context=context)
|
||||
vals['effective_date'] = datetime.date.today()
|
||||
vals['effective_date'] = date_obj.today(cursor, user,
|
||||
context=context)
|
||||
|
||||
if move.from_location.type == 'supplier' \
|
||||
and move.state != 'done' \
|
||||
|
||||
+21
-12
@@ -5,7 +5,6 @@ from trytond.model import ModelWorkflow, ModelView, ModelSQL, fields
|
||||
from trytond.report import CompanyReport
|
||||
from trytond.wizard import Wizard
|
||||
from trytond.backend import TableHandler
|
||||
import datetime
|
||||
|
||||
STATES = {
|
||||
'readonly': "state in ('cancel', 'done')",
|
||||
@@ -196,6 +195,8 @@ class PackingIn(ModelWorkflow, ModelSQL, ModelView):
|
||||
|
||||
def set_state_done(self, cursor, user, packing_id, context=None):
|
||||
move_obj = self.pool.get('stock.move')
|
||||
date_obj = self.pool.get('ir.date')
|
||||
|
||||
packing = self.browse(cursor, user, packing_id, context=context)
|
||||
move_obj.write(
|
||||
cursor, user,
|
||||
@@ -204,7 +205,7 @@ class PackingIn(ModelWorkflow, ModelSQL, ModelView):
|
||||
{'state': 'done'}, context)
|
||||
self.write(cursor, user, packing_id,{
|
||||
'state': 'done',
|
||||
'effective_date': datetime.date.today(),
|
||||
'effective_date': date_obj.today(cursor, user, context=context),
|
||||
}, context=context)
|
||||
|
||||
def set_state_cancel(self, cursor, user, packing_id, context=None):
|
||||
@@ -377,15 +378,17 @@ class PackingInReturn(ModelWorkflow, ModelSQL, ModelView):
|
||||
|
||||
def set_state_done(self, cursor, user, packing_id, context=None):
|
||||
move_obj = self.pool.get('stock.move')
|
||||
date_obj = self.pool.get('ir.date')
|
||||
|
||||
packing = self.browse(cursor, user, packing_id, context=context)
|
||||
move_obj.write(
|
||||
cursor, user,
|
||||
[m.id for m in packing.moves if m.state not in ('done', 'cancel')],
|
||||
{'state': 'done'}, context=context)
|
||||
self.write(cursor, user, packing_id,
|
||||
{'state': 'done',
|
||||
'effective_date': datetime.date.today()},
|
||||
context=context)
|
||||
self.write(cursor, user, packing_id, {
|
||||
'state': 'done',
|
||||
'effective_date': date_obj.today(cursor, user, context=context),
|
||||
}, context=context)
|
||||
|
||||
def set_state_cancel(self, cursor, user, packing_id, context=None):
|
||||
move_obj = self.pool.get('stock.move')
|
||||
@@ -645,6 +648,8 @@ class PackingOut(ModelWorkflow, ModelSQL, ModelView):
|
||||
|
||||
def set_state_done(self, cursor, user, packing_id, context=None):
|
||||
move_obj = self.pool.get('stock.move')
|
||||
date_obj = self.pool.get('ir.date')
|
||||
|
||||
packing = self.browse(cursor, user, packing_id, context=context)
|
||||
move_obj.write(
|
||||
cursor, user, [m.id for m in packing.outgoing_moves \
|
||||
@@ -652,7 +657,7 @@ class PackingOut(ModelWorkflow, ModelSQL, ModelView):
|
||||
{'state': 'done'}, context=context)
|
||||
self.write(cursor, user, packing_id, {
|
||||
'state': 'done',
|
||||
'effective_date': datetime.date.today(),
|
||||
'effective_date': date_obj.today(cursor, user, context=context),
|
||||
}, context=context)
|
||||
|
||||
def set_state_packed(self, cursor, user, packing_id, context=None):
|
||||
@@ -1038,6 +1043,8 @@ class PackingOutReturn(ModelWorkflow, ModelSQL, ModelView):
|
||||
|
||||
def set_state_done(self, cursor, user, packing_id, context=None):
|
||||
move_obj = self.pool.get('stock.move')
|
||||
date_obj = self.pool.get('ir.date')
|
||||
|
||||
packing = self.browse(cursor, user, packing_id, context=context)
|
||||
move_obj.write(
|
||||
cursor, user,
|
||||
@@ -1046,7 +1053,7 @@ class PackingOutReturn(ModelWorkflow, ModelSQL, ModelView):
|
||||
{'state': 'done'}, context)
|
||||
self.write(cursor, user, packing_id,{
|
||||
'state': 'done',
|
||||
'effective_date': datetime.date.today(),
|
||||
'effective_date': date_obj.today(cursor, user, context=context),
|
||||
}, context=context)
|
||||
|
||||
def set_state_cancel(self, cursor, user, packing_id, context=None):
|
||||
@@ -1269,14 +1276,16 @@ class PackingInternal(ModelWorkflow, ModelSQL, ModelView):
|
||||
|
||||
def set_state_done(self, cursor, user, packing_id, context=None):
|
||||
move_obj = self.pool.get('stock.move')
|
||||
date_obj = self.pool.get('ir.date')
|
||||
|
||||
packing = self.browse(cursor, user, packing_id, context=context)
|
||||
move_obj.write(
|
||||
cursor, user, [m.id for m in packing.moves], {'state': 'done'},
|
||||
context=context)
|
||||
self.write( cursor, user, packing_id,
|
||||
{'state': 'done',
|
||||
'effective_date': datetime.date.today()},
|
||||
context=context)
|
||||
self.write(cursor, user, packing_id, {
|
||||
'state': 'done',
|
||||
'effective_date': date_obj.today(cursor, user, context=context),
|
||||
}, context=context)
|
||||
|
||||
def set_state_cancel(self, cursor, user, packing_id, context=None):
|
||||
move_obj = self.pool.get('stock.move')
|
||||
|
||||
Reference in New Issue
Block a user