Reviewers: ,
Please review this at http://codereview.tryton.org/168002/
Affected files:
M CHANGELOG
M purchase.py
Index: CHANGELOG
===================================================================
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,5 @@
+* warehouse is not always required
+
Version 2.2.0 - 2011-10-25
* Bug fixes (see mercurial logs for details)
Index: purchase.py
===================================================================
--- a/purchase.py
+++ b/purchase.py
@@ -56,7 +56,7 @@
domain=[('party', '=', Eval('party'))], states=_STATES,
depends=['state', 'party'])
warehouse = fields.Many2One('stock.location', 'Warehouse',
- domain=[('type', '=', 'warehouse')], required=True, states=_STATES,
+ domain=[('type', '=', 'warehouse')], states=_STATES,
depends=_DEPENDS)
currency = fields.Many2One('currency.currency', 'Currency',
required=True,
states={
@@ -125,6 +125,8 @@
self._error_messages.update({
'invoice_addresse_required': 'Invoice addresses must be '
'defined for the quotation.',
+ 'warehouse_required': 'A warehouse must be defined for
the '
+ 'quotation.',
'missing_account_payable': 'It misses ' \
'an "Account Payable" on the party "%s"!',
})
@@ -153,6 +155,10 @@
"SET invoice_method = 'shipment' "\
"WHERE invoice_method = 'packing'")
+ table = TableHandler(cursor, self, module_name)
+ # Migration from 2.2: warehouse is no more required
+ table.not_null_action('warehouse', 'remove')
+
# Add index on create_date
table = TableHandler(cursor, self, module_name)
table.index_action('create_date', action='add')
@@ -595,6 +601,11 @@
purchase = self.browse(purchase_id)
if not purchase.invoice_address:
self.raise_user_error('invoice_addresse_required')
+ for line in purchase.lines:
+ if (not line.to_location
+ and line.product
+ and line.product.type in ('stockable', 'consumable')):
+ self.raise_user_error('warehouse_required')
return True
def set_reference(self, purchase_id):
@@ -956,6 +967,10 @@
move_done = fields.Function(fields.Boolean('Moves
Done'), 'get_move_done')
move_exception = fields.Function(fields.Boolean('Moves Exception'),
'get_move_exception')
+ from_location = fields.Function(fields.Many2One('stock.location',
+ 'From Location'), 'get_from_location')
+ to_location = fields.Function(fields.Many2One('stock.location',
+ 'To Location'), 'get_to_location')
def __init__(self):
super(PurchaseLine, self).__init__()
@@ -1192,6 +1207,21 @@
res[line.id] = Decimal('0.0')
return res
+ def get_from_location(self, ids, name):
+ result = {}
+ for line in self.browse(ids):
+ result[line.id] = line.purchase.party.supplier_location.id
+ return result
+
+ def get_to_location(self, ids, name):
+ result = {}
+ for line in self.browse(ids):
+ if line.purchase.warehouse:
+ result[line.id] = line.purchase.warehouse.input_location.id
+ else:
+ result[line.id] = False
+ return result
+
def get_invoice_line(self, line):
'''
Return invoice line values for purchase line
@@ -1293,8 +1323,8 @@
vals['quantity'] = quantity
vals['uom'] = line.unit.id
vals['product'] = line.product.id
- vals['from_location'] = line.purchase.party.supplier_location.id
- vals['to_location'] = line.purchase.warehouse.input_location.id
+ vals['from_location'] = line.from_location.id
+ vals['to_location'] = line.to_location.id
vals['state'] = 'draft'
vals['company'] = line.purchase.company.id
vals['unit_price'] = line.unit_price
--
[email protected] mailing list