Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP]backend link to attribute.attribute. #47

Open
wants to merge 6 commits into
base: 7.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions mmx_magento_attributes/product_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,45 +33,47 @@ class MMXProductDriver(orm.Model):
'backend_id',
'Magento Backend'),
'attribute_id': fields.many2one(
'magento.product.attribute', 'Magento Attribute', required=True),
'magento.product.attribute', 'Magento Attribute'),
'attr_id': fields.many2one(
'attribute.attribute', 'Attribute', required=True),
'magento_bind_ids': fields.one2many(
'magento.attribute.option', 'driver_id', 'Magento Option'),
}

def create(self, cr, uid, vals, context=None):
"""Create a Attribute Option for driver."""
magento_attribute_id = []
res_id = super(MMXProductDriver, self).create(
cr, uid, vals, context=context)

drvier_obj = self.browse(cr, uid, res_id, context=context)

driver_obj = self.browse(cr, uid, res_id, context=context)
magento_attribute_ids = driver_obj.attr_id.magento_bind_ids
backend_ids = self.resolve_2many_commands(
cr, uid, 'backend_ids', vals['backend_ids'], ['id'], context)

for backend_id in backend_ids:
attribute_id = vals['attribute_id']
option_vals = {
'name': vals['name'],
'backend_id': backend_id.get('id'),
'magento_attribute_id': attribute_id,
'value': drvier_obj.fullname,
'driver_id': res_id,
}
self.pool.get('magento.attribute.option').create(
cr, uid, option_vals, context=context)
magento_attr_id = False
for magento_attribute_id in magento_attribute_ids:
if magento_attribute_id.backend_id.id == backend_id.get('id'):
magento_attr_id = magento_attribute_id.id
option_vals = {
'name': vals['name'],
'backend_id': backend_id.get('id'),
'magento_attribute_id': magento_attr_id,
'value': driver_obj.fullname,
'driver_id': res_id,
}
self.pool.get('magento.attribute.option').create(
cr, uid, option_vals, context=context)

return res_id

def _get_default_attribute_id(self, cr, uid, context=None):
"""Get the x_mmx_driver(MMX)attribute_id as default value."""
"""Get the x_mmx_driver attr_id as default value."""
res = False
attribute_id = self.pool.get(
'magento.product.attribute').search(
cr, uid, [
('attribute_code', '=', 'x_mmx_driver'),
('backend_id', '=', 'MMX')
])
if attribute_id:
res = attribute_id[0]
attr_id = self.pool.get(
'attribute.attribute').search(cr, uid, [('name', '=', 'x_mmx_driver')])
if attr_id:
res = attr_id[0]
return res

def _get_all_backends(self, cr, uid, context=None):
Expand All @@ -80,7 +82,8 @@ def _get_all_backends(self, cr, uid, context=None):
ids = backend_pool.search(cr, uid, [], context=context)
return ids


_defaults = {
'backend_ids': _get_all_backends,
'attribute_id': _get_default_attribute_id,
'attr_id': _get_default_attribute_id,
}
3 changes: 2 additions & 1 deletion mmx_magento_attributes/product_driver_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<field name="arch" type="xml">
<data>
<field name="name" position="after">
<field name="attribute_id" groups="base.group_system" />
<field name="attr_id" groups="base.group_system" />
<field name="attribute_id" invisible="0" groups="base.group_system" />
<field name="backend_ids" groups="base.group_system" />
</field>
</data>
Expand Down
64 changes: 28 additions & 36 deletions mmx_magento_attributes/product_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#
##############################################################################
from openerp.osv import orm, fields
from openerp.osv.osv import except_osv


class MMXProductModel(orm.Model):
Expand All @@ -34,56 +33,49 @@ class MMXProductModel(orm.Model):
'backend_id',
'Magento Backend'),
'attribute_id': fields.many2one(
'magento.product.attribute', 'Magento Attribute', required=False),
'magento.product.attribute', 'Magento Attribute'),
'attr_id': fields.many2one(
'attribute.attribute', 'Attribute', required=True),
'magento_bind_ids': fields.one2many(
'magento.attribute.option', 'model_id', 'Magento Option'),
}

def create(self, cr, uid, vals, context=None):
"""Create a Attribute Option for model."""
magento_attribute_id = []
res_id = super(MMXProductModel, self).create(
cr, uid, vals, context=context)
pro_model = self.pool.get('product.model')
pro_model_obj = pro_model.browse(cr, uid, res_id, context=context)

pro_model_obj = self.browse(cr, uid, res_id, context=context)
magento_attribute_ids = pro_model_obj.attr_id.magento_bind_ids
backend_ids = self.resolve_2many_commands(
cr, uid, 'backend_ids', vals['backend_ids'], ['id'], context)

default_attribute_ids = self.pool.get(
'magento.product.attribute').search(
cr, uid, [('attribute_code', '=', 'x_mmx_model')])

if default_attribute_ids:
default_attribute_id = default_attribute_ids[0]

for backend_id in backend_ids:
attribute_id = default_attribute_id
option_vals = {
'name': ''.join([pro_model_obj.manufacturer_id.name, r'_', pro_model_obj.name]),
'backend_id': backend_id.get('id'),
'magento_attribute_id': attribute_id,
'value': vals['name'],
'model_id': res_id,
}
self.pool.get('magento.attribute.option').create(
cr, uid, option_vals, context=context)
else:
msg = "You have not created magento attribute 'x_mmx_model' yet !\n \
Please create one first."
raise except_osv(('Warning !'), (msg))
for backend_id in backend_ids:
magento_attr_id = False
for magento_attribute_id in magento_attribute_ids:
if magento_attribute_id.backend_id.id == backend_id.get('id'):
magento_attr_id = magento_attribute_id.id
option_vals = {
'name': ''.join([pro_model_obj.manufacturer_id.name, r'_', pro_model_obj.name]),
'backend_id': backend_id.get('id'),
'magento_attribute_id': magento_attr_id,
'value': vals['name'],
'model_id': res_id,
}
self.pool.get('magento.attribute.option').create(
cr, uid, option_vals, context=context)

return res_id

def _get_default_attribute_id(self, cr, uid, context=None):
"""Get the x_mmx_model(MMX)attribute_id as default value."""
"""Get the x_mmx_model attr_id as default value."""
res = False
attribute_id = self.pool.get(
'magento.product.attribute').search(
cr, uid, [
('attribute_code', '=', 'x_mmx_model'),
('backend_id', '=', 'MMX')
])
if attribute_id:
res = attribute_id[0]
attr_id = self.pool.get(
'attribute.attribute').search(
cr, uid, [('name', '=', 'x_mmx_model')])
if attr_id:
res = attr_id[0]
return res

def _get_all_backends(self, cr, uid, context=None):
Expand All @@ -94,5 +86,5 @@ def _get_all_backends(self, cr, uid, context=None):

_defaults = {
'backend_ids': _get_all_backends,
'attribute_id': _get_default_attribute_id,
'attr_id': _get_default_attribute_id,
}
3 changes: 2 additions & 1 deletion mmx_magento_attributes/product_model_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<field name="arch" type="xml">
<data>
<field name="name" position="after">
<field name="attribute_id" required="True" groups="base.group_system" />
<field name="attr_id" required="True" groups="base.group_system" />
<field name="attribute_id" invisible="0" groups="base.group_system" />
<field name="backend_ids" groups="base.group_system"/>
</field>
</data>
Expand Down
49 changes: 26 additions & 23 deletions mmx_magento_attributes/product_race.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,45 +33,48 @@ class MMXProductRace(orm.Model):
'backend_id',
'Magento Backend'),
'attribute_id': fields.many2one(
'magento.product.attribute', 'Magento Attribute', required=True),
'magento.product.attribute', 'Magento Attribute'),
'attr_id': fields.many2one(
'attribute.attribute', 'Attribute', required=True),
'magento_bind_ids': fields.one2many(
'magento.attribute.option', 'race_id', 'Magento Option'),
}

def create(self, cr, uid, vals, context=None):
"""Create a Attribute Option for race."""
magento_attribute_id = []
res_id = super(MMXProductRace, self).create(
cr, uid, vals, context=context)

race_obj = self.browse(cr, uid, res_id, context=context)

magento_attribute_ids = race_obj.attr_id.magento_bind_ids
backend_ids = self.resolve_2many_commands(
cr, uid, 'backend_ids', vals['backend_ids'], ['id'], context)

for backend_id in backend_ids:
attribute_id = vals['attribute_id']
option_vals = {
'name': vals['name'],
'backend_id': backend_id.get('id'),
'magento_attribute_id': attribute_id,
'value': race_obj.name,
'race_id': res_id,
}
self.pool.get('magento.attribute.option').create(
cr, uid, option_vals, context=context)
magento_attr_id = False
for magento_attribute_id in magento_attribute_ids:
if magento_attribute_id.backend_id.id == backend_id.get('id'):
magento_attr_id = magento_attribute_id.id
option_vals = {
'name': vals['name'],
'backend_id': backend_id.get('id'),
'magento_attribute_id': magento_attr_id,
'value': race_obj.name,
'race_id': res_id,
}
self.pool.get('magento.attribute.option').create(
cr, uid, option_vals, context=context)

return res_id

def _get_default_attribute_id(self, cr, uid, context=None):
"""Get the x_mmx_race_edition(MMX)attribute_id as default value."""
"""Get the x_mmx_race_edition attr_id as default value."""
res = False
attribute_id = self.pool.get(
'magento.product.attribute').search(
cr, uid, [
('attribute_code', '=', 'x_mmx_race_edition'),
('backend_id', '=', 'MMX')
])
if attribute_id:
res = attribute_id[0]
attr_id = self.pool.get(
'attribute.attribute').search(
cr, uid, [('name', '=', 'x_mmx_race_edition')])
if attr_id:
res = attr_id[0]
return res

def _get_all_backends(self, cr, uid, context=None):
Expand All @@ -82,5 +85,5 @@ def _get_all_backends(self, cr, uid, context=None):

_defaults = {
'backend_ids': _get_all_backends,
'attribute_id': _get_default_attribute_id,
'attr_id': _get_default_attribute_id,
}
3 changes: 2 additions & 1 deletion mmx_magento_attributes/product_race_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<field name="inherit_id" ref="mmx_product.product_race_form_view" />
<field name="arch" type="xml">
<field name="country_id" position="after">
<field name="attribute_id" string="Magento Attribute" groups="base.group_system"/>
<field name="attr_id" string="Attribute" groups="base.group_system"/>
<field name="attribute_id" invisible="0" groups="base.group_system"/>
<field name="backend_ids" string="Magento Backend" groups="base.group_system"/>
</field>
</field>
Expand Down
63 changes: 29 additions & 34 deletions mmx_magento_attributes/product_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,54 +36,49 @@ class MMXProductScale(orm.Model):
'backend_id',
'Magento Backend'),
'attribute_id': fields.many2one(
'magento.product.attribute', 'Magento Attribute', required=False),
'magento.product.attribute', 'Magento Attribute'),
'attr_id': fields.many2one(
'attribute.attribute', 'Attribute', required=True),
'magento_bind_ids': fields.one2many(
'magento.attribute.option', 'scale_id', 'Magento Option'),
}

def create(self, cr, uid, vals, context=None):
"""Create a Attribute Option for scale."""
magento_attribute_id = []
res_id = super(MMXProductScale, self).create(
cr, uid, vals, context=context)

scale_obj = self.browse(cr, uid, res_id, context=context)

backend_ids = self.resolve_2many_commands(
cr, uid, 'backend_ids', vals['backend_ids'], ['id'], context)

default_attribute_ids = self.pool.get(
'magento.product.attribute').search(
cr, uid, [('attribute_code', '=', 'x_mmx_scale')])

if default_attribute_ids:
default_attribute_id = default_attribute_ids[0]

for backend_id in backend_ids:
attribute_id = default_attribute_id
option_vals = {
'name': vals['name'],
'backend_id': backend_id.get('id'),
'magento_attribute_id': attribute_id,
'value': vals['name'],
'scale_id': res_id,
}
self.pool.get('magento.attribute.option').create(
cr, uid, option_vals, context=context)
else:
msg = "You have not created magento attribute 'x_mmx_scale' yet !\n \
Please create one first."
raise except_osv(('Warning !'), (msg))

magento_attribute_ids = scale_obj.attr_id.magento_bind_ids
for backend_id in backend_ids:
magento_attr_id = False
for magento_attribute_id in magento_attribute_ids:
if magento_attribute_id.backend_id.id == backend_id.get('id'):
magento_attr_id = magento_attribute_id.id
option_vals = {
'name': vals['name'],
'backend_id': backend_id.get('id'),
'magento_attribute_id': magento_attr_id,
'value': vals['name'],
'scale_id': res_id,
}
self.pool.get('magento.attribute.option').create(
cr, uid, option_vals, context=context)
return res_id

def _get_default_attribute_id(self, cr, uid, context=None):
"""Get the x_mmx_scale(MMX)attribute_id as default value."""
"""Get the x_mmx_scale attr_id as default value."""
res = False
attribute_id = self.pool.get(
'magento.product.attribute').search(
cr, uid, [
('attribute_code', '=', 'x_mmx_scale'),
('backend_id', '=', 'MMX')
])
if attribute_id:
res = attribute_id[0]
attr_id = self.pool.get(
'attribute.attribute').search(
cr, uid, [('name', '=', 'x_mmx_scale')])
if attr_id:
res = attr_id[0]
return res

def _get_all_backends(self, cr, uid, context=None):
Expand All @@ -94,5 +89,5 @@ def _get_all_backends(self, cr, uid, context=None):

_defaults = {
'backend_ids': _get_all_backends,
'attribute_id': _get_default_attribute_id,
'attr_id': _get_default_attribute_id,
}
3 changes: 2 additions & 1 deletion mmx_magento_attributes/product_scale_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<field name="inherit_id" ref="mmx_product.product_scale_form_view" />
<field name="arch" type="xml">
<field name="name" position="after">
<field name="attribute_id" required="True" string="Magento Attribute" groups="base.group_system"/>
<field name="attr_id" required="True" string="Attribute" groups="base.group_system"/>
<field name="attribute_id" invisible="0" groups="base.group_system"/>
<field name="backend_ids" string="Magento Backend" groups="base.group_system"/>
</field>
</field>
Expand Down