[IMP] website_quote: handle quote and website descriptions
Add field quote_description on product.template and turn website_description from sale.quote.line into a related. Overwrite write and create methods to synchronise both fields when setting a product. website_description on product.template is added by website_sale but there is no dependency relations between these modules so we need to define it in both modules.
This commit is contained in:
parent
8402625f10
commit
94b20608c6
|
@ -51,7 +51,7 @@ class sale_quote_line(osv.osv):
|
|||
'quote_id': fields.many2one('sale.quote.template', 'Quotation Template Reference', required=True, ondelete='cascade', select=True),
|
||||
'name': fields.text('Description', required=True, translate=True),
|
||||
'product_id': fields.many2one('product.product', 'Product', domain=[('sale_ok', '=', True)], required=True),
|
||||
'website_description': fields.html('Line Description', translate=True),
|
||||
'website_description': fields.related('product_id', 'product_tmpl_id', 'quote_description', string='Line Description', type='html', translate=True),
|
||||
'price_unit': fields.float('Unit Price', required=True, digits_compute= dp.get_precision('Product Price')),
|
||||
'discount': fields.float('Discount (%)', digits_compute= dp.get_precision('Discount')),
|
||||
'product_uom_qty': fields.float('Quantity', required=True, digits_compute= dp.get_precision('Product UoS')),
|
||||
|
@ -70,11 +70,30 @@ class sale_quote_line(osv.osv):
|
|||
vals.update({
|
||||
'price_unit': product_obj.list_price,
|
||||
'product_uom_id': product_obj.uom_id.id,
|
||||
'website_description': product_obj.website_description,
|
||||
'website_description': product_obj and (product_obj.quote_description or product_obj.website_description) or '',
|
||||
'name': name,
|
||||
})
|
||||
return {'value': vals}
|
||||
|
||||
def _inject_quote_description(self, cr, uid, values, context=None):
|
||||
values = dict(values or {})
|
||||
if not values.get('website_description') and values.get('product_id'):
|
||||
product = self.pool['product.product'].browse(cr, uid, values['product_id'], context=context)
|
||||
values['website_description'] = product.quote_description or product.website_description or ''
|
||||
return values
|
||||
|
||||
def create(self, cr, uid, values, context=None):
|
||||
values = self._inject_quote_description(cr, uid, values, context)
|
||||
ret = super(sale_quote_line, self).create(cr, uid, values, context=context)
|
||||
# hack because create don t make the job for a related field
|
||||
if values.get('website_description'):
|
||||
self.write(cr, uid, ret, {'website_description': values['website_description']}, context=context)
|
||||
return ret
|
||||
|
||||
def write(self, cr, uid, ids, values, context=None):
|
||||
values = self._inject_quote_description(cr, uid, values, context)
|
||||
return super(sale_quote_line, self).write(cr, uid, ids, values, context=context)
|
||||
|
||||
|
||||
class sale_order_line(osv.osv):
|
||||
_inherit = "sale.order.line"
|
||||
|
@ -84,19 +103,23 @@ class sale_order_line(osv.osv):
|
|||
'option_line_id': fields.one2many('sale.order.option', 'line_id', 'Optional Products Lines'),
|
||||
}
|
||||
|
||||
def _inject_website_description(self, cr, uid, values, context=None):
|
||||
def _inject_quote_description(self, cr, uid, values, context=None):
|
||||
values = dict(values or {})
|
||||
if not values.get('website_description') and values.get('product_id'):
|
||||
product = self.pool['product.product'].browse(cr, uid, values['product_id'], context=context)
|
||||
values['website_description'] = product.website_description
|
||||
values['website_description'] = product.quote_description or product.website_description
|
||||
return values
|
||||
|
||||
def create(self, cr, uid, values, context=None):
|
||||
values = self._inject_website_description(cr, uid, values, context)
|
||||
return super(sale_order_line, self).create(cr, uid, values, context=context)
|
||||
values = self._inject_quote_description(cr, uid, values, context)
|
||||
ret = super(sale_order_line, self).create(cr, uid, values, context=context)
|
||||
# hack because create don t make the job for a related field
|
||||
if values.get('website_description'):
|
||||
self.write(cr, uid, ret, {'website_description': values['website_description']}, context=context)
|
||||
return ret
|
||||
|
||||
def write(self, cr, uid, ids, values, context=None):
|
||||
values = self._inject_website_description(cr, uid, values, context)
|
||||
values = self._inject_quote_description(cr, uid, values, context)
|
||||
return super(sale_order_line, self).write(cr, uid, ids, values, context=context)
|
||||
|
||||
|
||||
|
@ -222,7 +245,7 @@ class sale_quote_option(osv.osv):
|
|||
product_obj = self.pool.get('product.product').browse(cr, uid, product, context=context)
|
||||
vals.update({
|
||||
'price_unit': product_obj.list_price,
|
||||
'website_description': product_obj.product_tmpl_id.website_description,
|
||||
'website_description': product_obj.product_tmpl_id.quote_description,
|
||||
'name': product_obj.name,
|
||||
'uom_id': product_obj.product_tmpl_id.uom_id.id,
|
||||
})
|
||||
|
@ -252,7 +275,7 @@ class sale_order_option(osv.osv):
|
|||
product_obj = self.pool.get('product.product').browse(cr, uid, product, context=context)
|
||||
vals.update({
|
||||
'price_unit': product_obj.list_price,
|
||||
'website_description': product_obj.product_tmpl_id.website_description,
|
||||
'website_description': product_obj and (product_obj.quote_description or product_obj.website_description),
|
||||
'name': product_obj.name,
|
||||
'uom_id': product_obj.product_tmpl_id.uom_id.id,
|
||||
})
|
||||
|
@ -260,6 +283,9 @@ class sale_order_option(osv.osv):
|
|||
|
||||
class product_template(osv.Model):
|
||||
_inherit = "product.template"
|
||||
|
||||
_columns = {
|
||||
'website_description': fields.html('Description for the website'),
|
||||
'website_description': fields.html('Description for the website'), # hack, if website_sale is not installed
|
||||
'quote_description': fields.html('Description for the quote'),
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue