Add company to Shipments

codereview74004
issue2078
This commit is contained in:
Nicolas Évrard committed 2011-10-04 18:17:41 +02:00
1 parent 38f7c797b3
commit 34128ae360
3 files changed
+242 -13

No files matched your search

+12 -7
View File
@@ -50,17 +50,22 @@ class Move(ModelSQL, ModelView):
required=True, states=STATES, depends=DEPENDS,
domain=[('type', 'not in', ('warehouse', 'view'))])
shipment_in = fields.Many2One('stock.shipment.in', 'Supplier Shipment',
readonly=True, select=1, ondelete='CASCADE')
domain=[('company', '=', Eval('company'))], depends=['company'],
readonly=True, select=1, ondelete='CASCADE')
shipment_out = fields.Many2One('stock.shipment.out', 'Customer Shipment',
readonly=True, select=1, ondelete='CASCADE')
domain=[('company', '=', Eval('company'))], depends=['company'],
readonly=True, select=1, ondelete='CASCADE')
shipment_out_return = fields.Many2One('stock.shipment.out.return',
'Customer Return Shipment', readonly=True, select=1,
ondelete='CASCADE')
'Customer Return Shipment', readonly=True, select=1,
domain=[('company', '=', Eval('company'))], depends=['company'],
ondelete='CASCADE')
shipment_in_return = fields.Many2One('stock.shipment.in.return',
'Supplier Return Shipment', readonly=True, select=1,
ondelete='CASCADE')
'Supplier Return Shipment', readonly=True, select=1,
domain=[('company', '=', Eval('company'))], depends=['company'],
ondelete='CASCADE')
shipment_internal = fields.Many2One('stock.shipment.internal',
'Internal Shipment', readonly=True, select=1, ondelete='CASCADE')
'Internal Shipment', readonly=True, select=1, ondelete='CASCADE',
domain=[('company', '=', Eval('company'))], depends=['company'])
planned_date = fields.Date("Planned Date", states={
'readonly': (In(Eval('state'), ['cancel', 'assigned', 'done'])
| Eval('shipment_in') | Eval('shipment_out')
+170 -6
View File
@@ -1,10 +1,12 @@
#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
import operator
import itertools
from trytond.model import ModelWorkflow, ModelView, ModelSQL, fields
from trytond.modules.company import CompanyReport
from trytond.wizard import Wizard
from trytond.backend import TableHandler
from trytond.pyson import Eval, Not, Equal, If, Or, And, Bool, In
from trytond.pyson import Eval, Not, Equal, If, Or, And, Bool, In, Get
from trytond.transaction import Transaction
from trytond.pool import Pool
@@ -23,6 +25,15 @@ class ShipmentIn(ModelWorkflow, ModelSQL, ModelView):
planned_date = fields.Date('Planned Date', states={
'readonly': Not(Equal(Eval('state'), 'draft')),
}, depends=['state'])
company = fields.Many2One('company.company', 'Company', required=True,
states={
'readonly': Not(Equal(Eval('state'), 'draft')),
},
domain=[
('id', If(In('company', Eval('context', {})), '=', '!='),
Get(Eval('context', {}), 'company', 0)),
],
depends=['state'])
reference = fields.Char("Reference", size=None, select=1,
states={
'readonly': Not(Equal(Eval('state'), 'draft')),
@@ -69,7 +80,8 @@ class ShipmentIn(ModelWorkflow, ModelSQL, ModelView):
}, depends=['state', 'warehouse']),
'get_inventory_moves', setter='set_inventory_moves')
moves = fields.One2Many('stock.move', 'shipment_in', 'Moves',
readonly=True)
domain=[('company', '=', Eval('company'))], readonly=True,
depends=['company'])
code = fields.Char("Code", size=None, select=1, readonly=True)
state = fields.Selection([
('draft', 'Draft'),
@@ -129,8 +141,26 @@ class ShipmentIn(ModelWorkflow, ModelSQL, ModelView):
for field in ('code', 'reference'):
table.index_action(field, action='remove', table=old_table)
# Migration from 2.0:
created_company = table.column_exist('company')
super(ShipmentIn, self).init(module_name)
# Migration from 2.0:
move_obj = Pool().get('stock.move')
if (not created_company
and TableHandler.table_exist(cursor, move_obj._table)):
cursor.execute('SELECT shipment.id, MAX(move.company) '
'FROM "%s" AS shipment '
'INNER JOIN "%s" AS move ON shipment.id = move.shipment_in '
'GROUP BY shipment.id '
'ORDER BY MAX(move.company)'
% (self._table, move_obj._table))
for company_id, shipment_ids in itertools.groupby(cursor.fetchall(),
operator.itemgetter(1)):
self.write(list(shipment_ids), {'company': company_id})
table.not_null_action('company', action='add')
# Add index on create_date
table = TableHandler(cursor, self, module_name)
table.index_action('create_date', action='add')
@@ -145,6 +175,9 @@ class ShipmentIn(ModelWorkflow, ModelSQL, ModelView):
return location_ids[0]
return False
def default_company(self):
return Transaction().context.get('company') or False
def on_change_supplier(self, values):
if not values.get('supplier'):
return {'contact_address': False}
@@ -390,6 +423,15 @@ class ShipmentInReturn(ModelWorkflow, ModelSQL, ModelView):
states={
'readonly': Not(Equal(Eval('state'), 'draft')),
}, depends=['state'])
company = fields.Many2One('company.company', 'Company', required=True,
states={
'readonly': Not(Equal(Eval('state'), 'draft')),
},
domain=[
('id', If(In('company', Eval('context', {})), '=', '!='),
Get(Eval('context', {}), 'company', 0)),
],
depends=['state'])
code = fields.Char("Code", size=None, select=1, readonly=True)
reference = fields.Char("Reference", size=None, select=1,
states={
@@ -413,11 +455,13 @@ class ShipmentInReturn(ModelWorkflow, ModelSQL, ModelView):
Not(Bool(Eval('from_location')))),
Bool(Eval('to_location'))),
},
domain=[('company', '=', Eval('company'))],
context={
'from_location': Eval('from_location'),
'to_location': Eval('to_location'),
'planned_date': Eval('planned_date'),
}, depends=['state', 'from_location', 'to_location'])
},
depends=['state', 'from_location', 'to_location', 'company'])
state = fields.Selection([
('draft', 'Draft'),
('cancel', 'Canceled'),
@@ -456,8 +500,27 @@ class ShipmentInReturn(ModelWorkflow, ModelSQL, ModelView):
for field in ('code', 'reference'):
table.index_action(field, action='remove', table=old_table)
# Migration from 2.0:
created_company = table.column_exist('company')
super(ShipmentInReturn, self).init(module_name)
# Migration from 2.0:
move_obj = Pool().get('stock.move')
if (not created_company
and TableHandler.table_exist(cursor, move_obj._table)):
cursor.execute('SELECT shipment.id, MAX(move.company) '
'FROM "%s" AS shipment '
'INNER JOIN "%s" AS move '
'ON shipment.id = move.shipment_in_return '
'GROUP BY shipment.id '
'ORDER BY MAX(move.company)'
% (self._table, move_obj._table))
for company_id, shipment_ids in itertools.groupby(cursor.fetchall(),
operator.itemgetter(1)):
self.write(list(shipment_ids), {'company': company_id})
table.not_null_action('company', action='add')
# Add index on create_date
table = TableHandler(cursor, self, module_name)
table.index_action('create_date', action='add')
@@ -506,6 +569,9 @@ class ShipmentInReturn(ModelWorkflow, ModelSQL, ModelView):
self._set_move_planned_date(ids)
return result
def default_company(self):
return Transaction().context.get('company') or False
def wkf_draft(self, shipment):
move_obj = Pool().get('stock.move')
self.write(shipment.id, {
@@ -611,6 +677,15 @@ class ShipmentOut(ModelWorkflow, ModelSQL, ModelView):
states={
'readonly': Not(Equal(Eval('state'), 'draft')),
}, depends=['state'])
company = fields.Many2One('company.company', 'Company', required=True,
states={
'readonly': Not(Equal(Eval('state'), 'draft')),
},
domain=[
('id', If(In('company', Eval('context', {})), '=', '!='),
Get(Eval('context', {}), 'company', 0)),
],
depends=['state'])
customer = fields.Many2One('party.party', 'Customer', required=True,
states={
'readonly': Or(Not(Equal(Eval('state'), 'draft')),
@@ -652,7 +727,8 @@ class ShipmentOut(ModelWorkflow, ModelSQL, ModelView):
}, depends=['state', 'warehouse']),
'get_inventory_moves', setter='set_inventory_moves')
moves = fields.One2Many('stock.move', 'shipment_out', 'Moves',
readonly=True)
domain=[('company', '=', Eval('company'))], depends=['company'],
readonly=True)
code = fields.Char("Code", size=None, select=1, readonly=True)
state = fields.Selection([
('draft', 'Draft'),
@@ -700,8 +776,27 @@ class ShipmentOut(ModelWorkflow, ModelSQL, ModelView):
for field in ('code', 'reference'):
table.index_action(field, action='remove', table=old_table)
# Migration from 2.0:
created_company = table.column_exist('company')
super(ShipmentOut, self).init(module_name)
# Migration from 2.0:
move_obj = Pool().get('stock.move')
if (not created_company
and TableHandler.table_exist(cursor, move_obj._table)):
move_obj = Pool().get('stock.move')
cursor.execute('SELECT shipment.id, MAX(move.company) '
'FROM "%s" AS shipment '
'INNER JOIN "%s" AS move ON shipment.id = move.shipment_out '
'GROUP BY shipment.id '
'ORDER BY MAX(move.company)'
% (self._table, move_obj._table))
for company_id, shipment_ids in itertools.groupby(cursor.fetchall(),
operator.itemgetter(1)):
self.write(list(shipment_ids), {'company': company_id})
table.not_null_action('company', action='add')
# Migration from 1.0 customer_location is no more used
table = TableHandler(cursor, self, module_name)
table.drop_column('customer_location', exception=True)
@@ -719,6 +814,9 @@ class ShipmentOut(ModelWorkflow, ModelSQL, ModelView):
return location_ids[0]
return False
def default_company(self):
return Transaction().context.get('company') or False
def on_change_customer(self, values):
if not values.get('customer'):
return {'delivery_address': False}
@@ -1070,6 +1168,15 @@ class ShipmentOutReturn(ModelWorkflow, ModelSQL, ModelView):
states={
'readonly': Not(Equal(Eval('state'), 'draft')),
}, depends=['state'])
company = fields.Many2One('company.company', 'Company', required=True,
states={
'readonly': Not(Equal(Eval('state'), 'draft')),
},
domain=[
('id', If(In('company', Eval('context', {})), '=', '!='),
Get(Eval('context', {}), 'company', 0)),
],
depends=['state'])
customer = fields.Many2One('party.party', 'Customer', required=True,
states={
'readonly': Or(Not(Equal(Eval('state'), 'draft')),
@@ -1110,7 +1217,8 @@ class ShipmentOutReturn(ModelWorkflow, ModelSQL, ModelView):
}, depends=['state', 'warehouse']),
'get_inventory_moves', setter='set_inventory_moves')
moves = fields.One2Many('stock.move', 'shipment_out_return', 'Moves',
readonly=True)
domain=[('company', '=', Eval('company'))], depends=['company'],
readonly=True)
code = fields.Char("Code", size=None, select=1, readonly=True)
state = fields.Selection([
('draft', 'Draft'),
@@ -1156,8 +1264,27 @@ class ShipmentOutReturn(ModelWorkflow, ModelSQL, ModelView):
for field in ('code', 'reference'):
table.index_action(field, action='remove', table=old_table)
# Migration from 2.0:
created_company = table.column_exist('company')
super(ShipmentOutReturn, self).init(module_name)
# Migration from 2.0:
move_obj = Pool().get('stock.move')
if (not created_company
and TableHandler.table_exist(cursor, move_obj._table)):
cursor.execute('SELECT shipment.id, MAX(move.company) '
'FROM "%s" AS shipment '
'INNER JOIN "%s" AS move '
'ON shipment.id = move.shipment_out_return '
'GROUP BY shipment.id '
'ORDER BY MAX(move.company)'
% (self._table, move_obj._table))
for company_id, shipment_ids in itertools.groupby(cursor.fetchall(),
operator.itemgetter(1)):
self.write(list(shipment_ids), {'company': company_id})
table.not_null_action('company', action='add')
# Add index on create_date
table = TableHandler(cursor, self, module_name)
table.index_action('create_date', action='add')
@@ -1172,6 +1299,9 @@ class ShipmentOutReturn(ModelWorkflow, ModelSQL, ModelView):
return location_ids[0]
return False
def default_company(self):
return Transaction().context.get('company') or False
def on_change_customer(self, values):
if not values.get('customer'):
return {'delivery_address': False}
@@ -1512,6 +1642,15 @@ class ShipmentInternal(ModelWorkflow, ModelSQL, ModelView):
states={
'readonly': Not(Equal(Eval('state'), 'draft')),
}, depends=['state'])
company = fields.Many2One('company.company', 'Company', required=True,
states={
'readonly': Not(Equal(Eval('state'), 'draft')),
},
domain=[
('id', If(In('company', Eval('context', {})), '=', '!='),
Get(Eval('context', {}), 'company', 0)),
],
depends=['state'])
code = fields.Char("Code", size=None, select=1, readonly=True)
reference = fields.Char("Reference", size=None, select=1,
states={
@@ -1540,11 +1679,14 @@ class ShipmentInternal(ModelWorkflow, ModelSQL, ModelView):
Not(Bool(Eval('from_location')))),
Bool(Eval('to_location'))),
},
domain=[('company', '=', Eval('company'))],
context={
'from_location': Eval('from_location'),
'to_location': Eval('to_location'),
'planned_date': Eval('planned_date'),
}, depends=['state', 'from_location', 'to_location', 'planned_date'])
},
depends=['state', 'from_location', 'to_location', 'planned_date',
'company'])
state = fields.Selection([
('draft', 'Draft'),
('cancel', 'Canceled'),
@@ -1576,8 +1718,27 @@ class ShipmentInternal(ModelWorkflow, ModelSQL, ModelView):
for field in ('code', 'reference'):
table.index_action(field, action='remove', table=old_table)
# Migration from 2.0:
created_company = table.column_exist('company')
super(ShipmentInternal, self).init(module_name)
# Migration from 2.0:
move_obj = Pool().get('stock.move')
if (not created_company
and TableHandler.table_exist(cursor, move_obj._table)):
cursor.execute('SELECT shipment.id, MAX(move.company) '
'FROM "%s" AS shipment '
'INNER JOIN "%s" AS move '
'ON shipment.id = move.shipment_internal '
'GROUP BY shipment.id '
'ORDER BY MAX(move.company)'
% (self._table, move_obj._table))
for company_id, shipment_ids in itertools.groupby(cursor.fetchall(),
operator.itemgetter(1)):
self.write(list(shipment_ids), {'company': company_id})
table.not_null_action('company', action='add')
# Add index on create_date
table = TableHandler(cursor, self, module_name)
table.index_action('create_date', action='add')
@@ -1585,6 +1746,9 @@ class ShipmentInternal(ModelWorkflow, ModelSQL, ModelView):
def default_state(self):
return 'draft'
def default_company(self):
return Transaction().context.get('company') or False
def button_draft(self, ids):
self.workflow_trigger_create(ids)
return True
+60
View File
@@ -23,6 +23,8 @@ this repository contains the full copyright notices and license terms. -->
<field name="planned_date"/>
<label name="effective_date"/>
<field name="effective_date"/>
<label name="company"/>
<field name="company"/>
<label name="warehouse"/>
<field name="warehouse"/>
<notebook colspan="6">
@@ -285,6 +287,8 @@ this repository contains the full copyright notices and license terms. -->
<field name="planned_date"/>
<label name="effective_date"/>
<field name="effective_date"/>
<label name="company"/>
<field name="company"/>
<label name="warehouse"/>
<field name="warehouse"/>
<notebook colspan="4">
@@ -488,6 +492,8 @@ this repository contains the full copyright notices and license terms. -->
<field name="planned_date"/>
<label name="effective_date"/>
<field name="effective_date"/>
<label name="company"/>
<field name="company"/>
<field name="moves" colspan="4"/>
<label name="state"/>
<field name="state"/>
@@ -660,6 +666,8 @@ this repository contains the full copyright notices and license terms. -->
<field name="planned_date"/>
<label name="effective_date"/>
<field name="effective_date"/>
<label name="company"/>
<field name="company"/>
<label name="warehouse"/>
<field name="warehouse"/>
<notebook colspan="6">
@@ -1532,5 +1540,57 @@ this repository contains the full copyright notices and license terms. -->
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="True"/>
</record>
<!-- Rule definition -->
<record model="ir.rule.group" id="rule_group_shipment_in">
<field name="model" search="[('model', '=', 'stock.shipment.in')]"/>
<field name="global_p" eval="True"/>
</record>
<record model="ir.rule" id="rule_shipment_in">
<field name="field" search="[('name', '=', 'company'), ('model.model', '=', 'stock.shipment.in')]"/>
<field name="operator">=</field>
<field name="operand">User/Current Company</field>
<field name="rule_group" ref="rule_group_shipment_in"/>
</record>
<record model="ir.rule.group" id="rule_group_shipment_in_return">
<field name="model" search="[('model', '=', 'stock.shipment.in.return')]"/>
<field name="global_p" eval="True"/>
</record>
<record model="ir.rule" id="rule_shipment_in_return">
<field name="field" search="[('name', '=', 'company'), ('model.model', '=', 'stock.shipment.in.return')]"/>
<field name="operator">=</field>
<field name="operand">User/Current Company</field>
<field name="rule_group" ref="rule_group_shipment_in_return"/>
</record>
<record model="ir.rule.group" id="rule_group_shipment_out">
<field name="model" search="[('model', '=', 'stock.shipment.out')]"/>
<field name="global_p" eval="True"/>
</record>
<record model="ir.rule" id="rule_shipment_out">
<field name="field" search="[('name', '=', 'company'), ('model.model', '=', 'stock.shipment.out')]"/>
<field name="operator">=</field>
<field name="operand">User/Current Company</field>
<field name="rule_group" ref="rule_group_shipment_out"/>
</record>
<record model="ir.rule.group" id="rule_group_shipment_out_return">
<field name="model" search="[('model', '=', 'stock.shipment.out.return')]"/>
<field name="global_p" eval="True"/>
</record>
<record model="ir.rule" id="rule_shipment_out_return">
<field name="field" search="[('name', '=', 'company'), ('model.model', '=', 'stock.shipment.out.return')]"/>
<field name="operator">=</field>
<field name="operand">User/Current Company</field>
<field name="rule_group" ref="rule_group_shipment_out_return"/>
</record>
<record model="ir.rule.group" id="rule_group_shipment_internal">
<field name="model" search="[('model', '=', 'stock.shipment.internal')]"/>
<field name="global_p" eval="True"/>
</record>
<record model="ir.rule" id="rule_shipment_internal">
<field name="field" search="[('name', '=', 'company'), ('model.model', '=', 'stock.shipment.internal')]"/>
<field name="operator">=</field>
<field name="operand">User/Current Company</field>
<field name="rule_group" ref="rule_group_shipment_internal"/>
</record>
</data>
</tryton>