[FIX] product: add menu item to attributes and attribute values. Adding constraint to prevent deleting attributes with references to products.
This commit is contained in:
parent
e3d9db2bab
commit
4117c9c3ed
|
@ -364,7 +364,7 @@ class product_attribute_value(osv.osv):
|
|||
_columns = {
|
||||
'sequence': fields.integer('Sequence', help="Determine the display order"),
|
||||
'name': fields.char('Value', translate=True, required=True),
|
||||
'attribute_id': fields.many2one('product.attribute', 'Attribute', required=True),
|
||||
'attribute_id': fields.many2one('product.attribute', 'Attribute', required=True, ondelete='cascade'),
|
||||
'product_ids': fields.many2many('product.product', id1='att_id', id2='prod_id', string='Variants', readonly=True),
|
||||
'price_extra': fields.function(_get_price_extra, type='float', string='Attribute Price Extra',
|
||||
fnct_inv=_set_price_extra,
|
||||
|
@ -378,20 +378,26 @@ class product_attribute_value(osv.osv):
|
|||
_defaults = {
|
||||
'price_extra': 0.0,
|
||||
}
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
ctx = dict(context or {}, active_test=False)
|
||||
product_ids = self.pool['product.product'].search(cr, uid, [('attribute_value_ids', 'in', ids)], context=ctx)
|
||||
if product_ids:
|
||||
raise osv.except_osv(_('Integrity Error!'), _('The operation cannot be completed:\nYou trying to delete an attribute value with a reference on a product variant.'))
|
||||
return super(product_attribute_value, self).unlink(cr, uid, ids, context=context)
|
||||
|
||||
class product_attribute_price(osv.osv):
|
||||
_name = "product.attribute.price"
|
||||
_columns = {
|
||||
'product_tmpl_id': fields.many2one('product.template', 'Product Template', required=True),
|
||||
'value_id': fields.many2one('product.attribute.value', 'Product Attribute Value', required=True),
|
||||
'product_tmpl_id': fields.many2one('product.template', 'Product Template', required=True, ondelete='cascade'),
|
||||
'value_id': fields.many2one('product.attribute.value', 'Product Attribute Value', required=True, ondelete='cascade'),
|
||||
'price_extra': fields.float('Price Extra', digits_compute=dp.get_precision('Product Price')),
|
||||
}
|
||||
|
||||
class product_attribute_line(osv.osv):
|
||||
_name = "product.attribute.line"
|
||||
_columns = {
|
||||
'product_tmpl_id': fields.many2one('product.template', 'Product Template', required=True),
|
||||
'attribute_id': fields.many2one('product.attribute', 'Attribute', required=True),
|
||||
'product_tmpl_id': fields.many2one('product.template', 'Product Template', required=True, ondelete='cascade'),
|
||||
'attribute_id': fields.many2one('product.attribute', 'Attribute', required=True, ondelete='restrict'),
|
||||
'value_ids': fields.many2many('product.attribute.value', id1='line_id', id2='val_id', string='Product Attribute Value'),
|
||||
}
|
||||
|
||||
|
@ -898,7 +904,7 @@ class product_product(osv.osv):
|
|||
'product.template': (_get_name_template_ids, ['name'], 10),
|
||||
'product.product': (lambda self, cr, uid, ids, c=None: ids, [], 10),
|
||||
}, select=True),
|
||||
'attribute_value_ids': fields.many2many('product.attribute.value', id1='prod_id', id2='att_id', string='Attributes', readonly=True),
|
||||
'attribute_value_ids': fields.many2many('product.attribute.value', id1='prod_id', id2='att_id', string='Attributes', readonly=True, ondelete='restrict'),
|
||||
|
||||
# image: all image fields are base64 encoded and PIL-supported
|
||||
'image_variant': fields.binary("Variant Image",
|
||||
|
|
|
@ -193,6 +193,7 @@
|
|||
<record id="variants_template_tree_view" model="ir.ui.view">
|
||||
<field name="name">variants.template.tree</field>
|
||||
<field name="model">product.attribute.value</field>
|
||||
<field name="priority" eval="2"/>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Variant Values" editable="top">
|
||||
<field name="sequence" widget="handle"/>
|
||||
|
@ -214,7 +215,7 @@
|
|||
|
||||
<!-- product product -->
|
||||
|
||||
<menuitem id="prod_config_main" name="Product Variants" parent="base.menu_base_config" sequence="70" groups="base.group_no_one"/>
|
||||
<menuitem id="prod_config_main" name="Product Categories & Attributes" parent="base.menu_base_config" sequence="70" groups="base.group_no_one"/>
|
||||
|
||||
<record id="product_search_form_view" model="ir.ui.view">
|
||||
<field name="name">product.product.search</field>
|
||||
|
@ -385,6 +386,54 @@
|
|||
|
||||
<!-- -->
|
||||
|
||||
<record id="attribute_tree_view" model="ir.ui.view">
|
||||
<field name="name">product.attribute.tree</field>
|
||||
<field name="model">product.attribute</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Variant Values" editable="top">
|
||||
<field name="name"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="attribute_action" model="ir.actions.act_window">
|
||||
<field name="name">Attributes</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">product.attribute</field>
|
||||
<field name="view_mode">tree</field>
|
||||
<field name="view_type">form</field>
|
||||
</record>
|
||||
|
||||
<menuitem action="attribute_action"
|
||||
id="menu_attribute_action"
|
||||
parent="product.prod_config_main" sequence="9" />
|
||||
|
||||
<record id="variants_tree_view" model="ir.ui.view">
|
||||
<field name="name">product.attribute.value.tree</field>
|
||||
<field name="model">product.attribute.value</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Variant Values" editable="top">
|
||||
<field name="sequence" widget="handle"/>
|
||||
<field name="attribute_id"/>
|
||||
<field name="name"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="variants_action" model="ir.actions.act_window">
|
||||
<field name="name">Attribute Values</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">product.attribute.value</field>
|
||||
<field name="view_mode">tree</field>
|
||||
<field name="view_type">form</field>
|
||||
</record>
|
||||
|
||||
<menuitem action="variants_action"
|
||||
id="menu_variants_action"
|
||||
parent="product.prod_config_main" sequence="10" />
|
||||
|
||||
<!-- -->
|
||||
|
||||
<record id="product_normal_action_sell" model="ir.actions.act_window">
|
||||
<field name="name">Product Variants</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
|
|
|
@ -45,6 +45,16 @@
|
|||
</field>
|
||||
</field>
|
||||
</record>
|
||||
<record id="variants_tree_view" model="ir.ui.view">
|
||||
<field name="name">variants.template.tree</field>
|
||||
<field name="model">product.attribute.value</field>
|
||||
<field name="inherit_id" ref="product.variants_tree_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="name" position="after">
|
||||
<field name="color"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Product Public Categories -->
|
||||
<record id="product_public_category_form_view" model="ir.ui.view">
|
||||
|
|
Loading…
Reference in New Issue