Reviewers: ,
Please review this at http://codereview.tryton.org/185003/ Affected files: M CHANGELOG M sale.py M sale.xml Index: CHANGELOG =================================================================== --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add a Function field delivery_date to sale line * warehouse is not always required Version 2.2.0 - 2011-10-25 Index: sale.py =================================================================== --- a/sale.py +++ b/sale.py @@ -1126,6 +1126,9 @@ 'From Location'), 'get_from_location') to_location = fields.Function(fields.Many2One('stock.location', 'To Location'), 'get_to_location') + delivery_date = fields.Function(fields.Date('Delivery Date', + on_change_with=['product', '_parent_sale.sale_date']), + 'get_delivery_date') def __init__(self): super(SaleLine, self).__init__() @@ -1375,6 +1378,25 @@ result[line.id] = line.sale.party.customer_location.id return result + def _compute_delivery_date(self, product, date): + product_obj = Pool().get('product.product') + return product_obj.compute_delivery_date(product, date=date) + + def on_change_with_delivery_date(self, values): + product_obj = Pool().get('product.product') + if values.get('product'): + product = product_obj.browse(values['product']) + return self._compute_delivery_date(product, + values.get('_parent_sale.sale_date')) + return False + + def get_delivery_date(self, ids, name): + dates = {} + for line in self.browse(ids): + dates[line.id] = self._compute_delivery_date(line.product, + line.sale.sale_date) + return dates + def get_invoice_line(self, line): ''' Return invoice line values for sale line @@ -1482,8 +1504,7 @@ res['company'] = line.sale.company.id res['unit_price'] = line.unit_price res['currency'] = line.sale.currency.id - res['planned_date'] = product_obj.compute_delivery_date( - line.product) + res['planned_date'] = line.delivery_date return res SaleLine() Index: sale.xml =================================================================== --- a/sale.xml +++ b/sale.xml @@ -824,6 +824,8 @@ <field name="unit_price"/> <label name="amount"/> <field name="amount"/> + <label name="delivery_date"/> + <field name="delivery_date"/> <field name="taxes" colspan="4"/> </page> <page string="Notes" id="notes"> -- tryton-dev@googlegroups.com mailing list