Reviewers: ,
Please review this at http://codereview.tryton.org/160008/
Affected files:
M CHANGELOG
M sale.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)
* Add delivery time on product
Index: sale.py
===================================================================
--- a/sale.py
+++ b/sale.py
@@ -69,7 +69,7 @@
},
depends=['party', 'state'])
warehouse = fields.Many2One('stock.location', 'Warehouse',
- domain=[('type', '=', 'warehouse')], required=True, states={
+ domain=[('type', '=', 'warehouse')], states={
'readonly': Eval('state') != 'draft',
},
depends=['state'])
@@ -155,6 +155,8 @@
'wrong_method': 'Wrong combination of method!',
'addresses_required': 'Invoice and Shipment addresses must be '
'defined for the quotation.',
+ 'warehouse_required': 'Warehouse must be defined for the '
+ 'quotation.',
'missing_account_receivable': 'It misses '
'an "Account Receivable" on the party "%s"!',
})
@@ -645,6 +647,11 @@
sale = self.browse(sale_id)
if not sale.invoice_address or not sale.shipment_address:
self.raise_user_error('addresses_required')
+ for line in sale.lines:
+ if (not line.from_location
+ and line.product
+ and line.product.type in ('stockable', 'consumable')):
+ self.raise_user_error('warehouse_required')
return True
def set_reference(self, sale_id):
@@ -1108,6 +1115,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(SaleLine, self).__init__()
@@ -1337,6 +1348,21 @@
res[line.id] = Decimal('0.0')
return res
+ def get_from_location(self, ids, name):
+ result = {}
+ for line in self.browse(ids):
+ if line.sale.warehouse:
+ result[line.id] = line.sale.warehouse.output_location.id
+ else:
+ result[line.id] = False
+ return result
+
+ def get_to_location(self, ids, name):
+ result = {}
+ for line in self.browse(ids):
+ result[line.id] = line.sale.party.customer_location.id
+ return result
+
def get_invoice_line(self, line):
'''
Return invoice line values for sale line
@@ -1438,8 +1464,8 @@
res['quantity'] = quantity
res['uom'] = line.unit.id
res['product'] = line.product.id
- res['from_location'] = line.sale.warehouse.output_location.id
- res['to_location'] = line.sale.party.customer_location.id
+ res['from_location'] = line.from_location.id
+ res['to_location'] = line.to_location.id
res['state'] = 'draft'
res['company'] = line.sale.company.id
res['unit_price'] = line.unit_price
--
[email protected] mailing list