Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

[13.0][FIX]Custom values when update the config #185

Open
wants to merge 2 commits into
base: 13.0
Choose a base branch
from
Open
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
24 changes: 23 additions & 1 deletion product_configurator_sale/wizard/product_configurator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo import fields, models
from odoo import fields, models, api


class ProductConfiguratorSale(models.TransientModel):
Expand Down Expand Up @@ -53,3 +53,25 @@ def action_config_done(self):
else:
self.order_id.write({"order_line": [(0, 0, values)]})
return

@api.model
def create(self, vals):
if self.env.context.get('default_order_line_id', False):
sale_line = self.env["sale.order.line"].browse(
self.env.context['default_order_line_id'])
if sale_line.custom_value_ids:
vals['custom_value_ids'] = self._get_custom_values(
sale_line.config_session_id)
res = super(ProductConfiguratorSale, self).create(vals)
return res

def _get_custom_values(self, session):
custom_values = [(5,)] + [(0, 0, {
'attribute_id': value_custom.attribute_id.id,
'value': value_custom.value,
'attachment_ids': [(4, attach.id)
for attach in value_custom.attachment_ids],
}) for value_custom in session.custom_value_ids]
return custom_values