changes
This commit is contained in:
@@ -29,6 +29,8 @@ class WooProductMap(models.Model):
|
||||
woo_regular_price = fields.Float(string='WC Standard Price', digits='Product Price')
|
||||
woo_sale_price = fields.Float(string='WC Sale Price', digits='Product Price')
|
||||
woo_permalink = fields.Char(string='WC Product URL')
|
||||
woo_category_id = fields.Integer(string='WC Category ID')
|
||||
woo_category_name = fields.Char(string='WC Category')
|
||||
woo_parent_id = fields.Integer()
|
||||
is_variation = fields.Boolean()
|
||||
sync_price = fields.Boolean(default=True)
|
||||
@@ -312,6 +314,54 @@ class WooProductMap(models.Model):
|
||||
pass
|
||||
return client.create_attribute_term(attr_id, {'name': term_name})
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Create in Odoo (from unmapped WC product)
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
def action_create_in_odoo(self):
|
||||
"""Create an Odoo product from WC mapping data, link the mapping, and
|
||||
return the new product ID so the JS can open the form."""
|
||||
self.ensure_one()
|
||||
if self.product_id:
|
||||
raise UserError("This mapping already has an Odoo product linked.")
|
||||
|
||||
wc_price = self.woo_sale_price or self.woo_regular_price or 0.0
|
||||
|
||||
# Resolve Odoo category from WC category mapping
|
||||
categ_id = False
|
||||
if self.woo_category_id and self.instance_id:
|
||||
cat_map = self.env['woo.category.map'].search([
|
||||
('instance_id', '=', self.instance_id.id),
|
||||
('woo_category_id', '=', self.woo_category_id),
|
||||
('odoo_category_id', '!=', False),
|
||||
], limit=1)
|
||||
if cat_map:
|
||||
categ_id = cat_map.odoo_category_id.id
|
||||
|
||||
product_vals = {
|
||||
'name': (self.woo_product_name or 'New Product').upper(),
|
||||
'default_code': self.woo_sku or '',
|
||||
'list_price': wc_price,
|
||||
'type': 'consu',
|
||||
}
|
||||
if categ_id:
|
||||
product_vals['categ_id'] = categ_id
|
||||
|
||||
product = self.env['product.product'].create(product_vals)
|
||||
|
||||
self.write({
|
||||
'product_id': product.id,
|
||||
'state': 'mapped',
|
||||
})
|
||||
|
||||
if self.instance_id:
|
||||
self.instance_id._log_sync(
|
||||
'product', 'woo_to_odoo', product.name, 'success',
|
||||
'Created Odoo product from WC #%s' % self.woo_product_id,
|
||||
)
|
||||
|
||||
return {'product_id': product.id}
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# SKU Sync
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user