[IMP] product: cleaned form in create mode. Moreover generally
changing the template is not possible anymore; create a new tempalte or a new variant instead. When creating a new product, you will always create a new template. Added the link to the template from the product form view. Cleaned some code (code move). bzr revid: tde@openerp.com-20140122170218-6j2sixoxvvbbxvhd
This commit is contained in:
parent
363f8561af
commit
055932fc6a
|
@ -23,12 +23,10 @@ import math
|
|||
import re
|
||||
|
||||
from _common import rounding
|
||||
from lxml import etree
|
||||
|
||||
from openerp.osv.orm import setup_modifiers
|
||||
from openerp import SUPERUSER_ID
|
||||
from openerp import tools
|
||||
from openerp.osv import osv, fields
|
||||
from openerp.osv import osv, orm, fields
|
||||
from openerp.tools.translate import _
|
||||
|
||||
import openerp.addons.decimal_precision as dp
|
||||
|
@ -519,6 +517,13 @@ class product_template(osv.osv):
|
|||
|
||||
|
||||
class product_product(osv.osv):
|
||||
_name = "product.product"
|
||||
_description = "Product"
|
||||
_table = "product_product"
|
||||
_inherits = {'product.template': 'product_tmpl_id'}
|
||||
_inherit = ['mail.thread']
|
||||
_order = 'default_code,name_template'
|
||||
|
||||
def view_header_get(self, cr, uid, view_id, view_type, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
|
@ -648,7 +653,6 @@ class product_product(osv.osv):
|
|||
}
|
||||
return result
|
||||
|
||||
|
||||
def _get_name_template_ids(self, cr, uid, ids, context=None):
|
||||
result = set()
|
||||
template_ids = self.pool.get('product.product').search(cr, uid, [('product_tmpl_id', 'in', ids)])
|
||||
|
@ -656,19 +660,6 @@ class product_product(osv.osv):
|
|||
result.add(el)
|
||||
return list(result)
|
||||
|
||||
_defaults = {
|
||||
'active': lambda *a: 1,
|
||||
'price_extra': lambda *a: 0.0,
|
||||
'price_margin': lambda *a: 1.0,
|
||||
'color': 0,
|
||||
}
|
||||
|
||||
_name = "product.product"
|
||||
_description = "Product"
|
||||
_table = "product_product"
|
||||
_inherits = {'product.template': 'product_tmpl_id'}
|
||||
_inherit = ['mail.thread']
|
||||
_order = 'default_code,name_template'
|
||||
_columns = {
|
||||
'qty_available': fields.function(_product_qty_available, type='float', string='Quantity On Hand'),
|
||||
'virtual_available': fields.function(_product_virtual_available, type='float', string='Quantity Available'),
|
||||
|
@ -692,8 +683,7 @@ class product_product(osv.osv):
|
|||
'name_template': fields.related('product_tmpl_id', 'name', string="Template Name", type='char', size=128, store={
|
||||
'product.template': (_get_name_template_ids, ['name'], 10),
|
||||
'product.product': (lambda self, cr, uid, ids, c=None: ids, [], 10),
|
||||
|
||||
}, select=True),
|
||||
}, select=True),
|
||||
'color': fields.integer('Color Index'),
|
||||
'seller_info_id': fields.function(_calc_seller, type='many2one', relation="product.supplierinfo", string="Supplier Info", multi="seller_info"),
|
||||
'seller_delay': fields.function(_calc_seller, type='integer', string='Supplier Lead Time', multi="seller_info", help="This is the average delay in days between the purchase order confirmation and the reception of goods for this product and for the default supplier. It is used by the scheduler to order requests based on reordering delays."),
|
||||
|
@ -701,6 +691,14 @@ class product_product(osv.osv):
|
|||
'seller_id': fields.function(_calc_seller, type='many2one', relation="res.partner", string='Main Supplier', help="Main Supplier who has highest priority in Supplier List.", multi="seller_info"),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'active': lambda *a: 1,
|
||||
'price_extra': lambda *a: 0.0,
|
||||
'price_margin': lambda *a: 1.0,
|
||||
'color': 0,
|
||||
'is_only_child': True,
|
||||
}
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
unlink_ids = []
|
||||
unlink_product_tmpl_ids = []
|
||||
|
@ -726,22 +724,11 @@ class product_product(osv.osv):
|
|||
return {'value': {'uom_po_id': uom_id}}
|
||||
return False
|
||||
|
||||
def onchange_product_tmpl_id(self, cr, uid, ids, template_id, context=None):
|
||||
res = {}
|
||||
if template_id:
|
||||
template = self.pool.get('product.template').browse(cr, uid, template_id, context=context)
|
||||
res['value'] = {
|
||||
'name': template.name,
|
||||
'lst_price': template.list_price,
|
||||
}
|
||||
return res
|
||||
|
||||
def _check_ean_key(self, cr, uid, ids, context=None):
|
||||
for product in self.read(cr, uid, ids, ['ean13'], context=context):
|
||||
res = check_ean(product['ean13'])
|
||||
return res
|
||||
|
||||
|
||||
_constraints = [(_check_ean_key, 'You provided an invalid "EAN13 Barcode" reference. You may use the "Internal Reference" field instead.', ['ean13'])]
|
||||
|
||||
def on_order(self, cr, uid, ids, orderline, quantity):
|
||||
|
@ -896,6 +883,15 @@ class product_product(osv.osv):
|
|||
args.append((('categ_id', 'child_of', context['search_default_categ_id'])))
|
||||
return super(product_product, self).search(cr, uid, args, offset=offset, limit=limit, order=order, context=context, count=count)
|
||||
|
||||
def open_product_template(self, cr, uid, ids, context=None):
|
||||
""" Utility method used to add an "Open Template" button in product views """
|
||||
product = self.browse(cr, uid, ids[0], context=context)
|
||||
return {'type': 'ir.actions.act_window',
|
||||
'res_model': 'product.template',
|
||||
'view_mode': 'form',
|
||||
'res_id': product.product_tmpl_id.id,
|
||||
'target': 'new'}
|
||||
|
||||
|
||||
class product_packaging(osv.osv):
|
||||
_name = "product.packaging"
|
||||
|
|
|
@ -60,8 +60,9 @@
|
|||
<field name="arch" type="xml">
|
||||
<form string="Product" version="7.0">
|
||||
<sheet>
|
||||
<field name="is_only_child" invisible="0"/>
|
||||
<field name="image_medium" widget="image" class="oe_avatar oe_left"/>
|
||||
<field name="is_only_child" invisible="1"/>
|
||||
<field name="image_medium" widget="image" class="oe_avatar oe_left"
|
||||
attrs="{'readonly': [('is_only_child', '=', False)]}"/>
|
||||
<div class="oe_title">
|
||||
<div class="oe_edit_only">
|
||||
<label for="name" name='label_name' string="Product Name"
|
||||
|
@ -73,17 +74,16 @@
|
|||
<field name="name" class="oe_inline"
|
||||
attrs="{'required': [('is_only_child', '=', True)],
|
||||
'invisible': [('is_only_child', '=', False)]}"/>
|
||||
<field name="product_tmpl_id" class="oe_inline"
|
||||
attrs="{'required': [('is_only_child', '=', False)],
|
||||
'invisible': [('is_only_child', '=', True)]}"
|
||||
on_change="onchange_product_tmpl_id(product_tmpl_id)"/>
|
||||
<field name="product_tmpl_id" class="oe_inline" readonly="1" required="0"
|
||||
attrs="{'invisible': [('is_only_child', '=', True)]}"/>
|
||||
<span attrs="{'invisible':[('variants','=',False)]}" groups="product.group_product_variant"> - </span>
|
||||
<field name="variants" placeholder="Variant Name"
|
||||
groups="product.group_product_variant" class="oe_inline"/>
|
||||
</h1>
|
||||
<span attrs="{'invisible': [('is_only_child', '=', True)]}">
|
||||
Manage some of the product attributes on the
|
||||
<a>template form</a>
|
||||
<p>Generic product settings are managed on
|
||||
<button name="open_product_template" type="object" string="the template" class="oe_link"/>
|
||||
</p>
|
||||
</span>
|
||||
<label for="categ_id" class="oe_edit_only"/>
|
||||
<h2><field name="categ_id" attrs="{'readonly': [('is_only_child', '=', False)]}"/></h2>
|
||||
|
|
Loading…
Reference in New Issue