-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[ADD] new_product_type: Added sub-products to a particular product #833
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
base: 18.0
Are you sure you want to change the base?
Conversation
…new fields In the new_producttype module created in the product form to add sub-products field in specific products and in sale.order.line added a button in that by clicking on it, created a wizard of sub_product linked with the main product.
In the new_producttype module, get the sub-products associated with the product on sale.order.line using wizard and added that the sub_products directly in sale.order.line and made the parent line ondelete=cascade to delete sub_product_lines on deletion of parent_line
In the new_producttype module , added sub_products in invoice When the boolean is true, and also added sub_products in customer preview.
@@ -0,0 +1,18 @@ | |||
{ | |||
'name': "New Product Type", | |||
'category': '', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shoud not be empty.you can either remove it.
_inherit = 'sale.order.line' | ||
|
||
is_kit = fields.Boolean(string='Is kit', related='product_id.is_kit') | ||
main_product_line_id = fields.Many2one("sale.order.line", ondelete="cascade") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow the same quote in the file. if you are using '
then you have to apply it to all fields.
sale_order_line = self.env["sale.order.line"].browse(sale_order_line_id) | ||
existing_lines = self.env["sale.order.line"].search( | ||
[("main_product_line_id", "=", sale_order_line_id)] | ||
) | ||
line_values = [] | ||
if existing_lines: | ||
for sub_product in existing_lines: | ||
curr_product = self.env["sub.product.line.kit.wizard"].create( | ||
{ | ||
"product_id": sub_product.product_id.id, | ||
"price": sub_product.price_unit, | ||
"quantity": sub_product.product_uom_qty, | ||
} | ||
) | ||
line_values.append(Command.link(curr_product.id)) | ||
else: | ||
for sub_product in sale_order_line.product_id.sub_products_ids: | ||
curr_product = self.env["sub.product.line.kit.wizard"].create( | ||
{ | ||
"product_id": sub_product.id, | ||
"price": sub_product.list_price, | ||
"quantity": 1, | ||
} | ||
) | ||
line_values.append(Command.link(curr_product.id)) | ||
res["sub_products_ids"] = line_values | ||
res["sale_order_line_id"] = sale_order_line_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sale_order_line = self.env["sale.order.line"].browse(sale_order_line_id) | |
existing_lines = self.env["sale.order.line"].search( | |
[("main_product_line_id", "=", sale_order_line_id)] | |
) | |
line_values = [] | |
if existing_lines: | |
for sub_product in existing_lines: | |
curr_product = self.env["sub.product.line.kit.wizard"].create( | |
{ | |
"product_id": sub_product.product_id.id, | |
"price": sub_product.price_unit, | |
"quantity": sub_product.product_uom_qty, | |
} | |
) | |
line_values.append(Command.link(curr_product.id)) | |
else: | |
for sub_product in sale_order_line.product_id.sub_products_ids: | |
curr_product = self.env["sub.product.line.kit.wizard"].create( | |
{ | |
"product_id": sub_product.id, | |
"price": sub_product.list_price, | |
"quantity": 1, | |
} | |
) | |
line_values.append(Command.link(curr_product.id)) | |
res["sub_products_ids"] = line_values | |
res["sale_order_line_id"] = sale_order_line_id | |
sale_order_line = self.env["sale.order.line"].browse(sale_order_line_id) | |
existing_lines = self.env["sale.order.line"].search([ | |
("main_product_line_id", "=", sale_order_line_id) | |
]) | |
sub_product_line_wizard = self.env["sub.product.line.kit.wizard"] | |
line_values = [] | |
if existing_lines: | |
vals_list = [ | |
{ | |
"product_id": line.product_id.id, | |
"price": line.price_unit, | |
"quantity": line.product_uom_qty, | |
} | |
for line in existing_lines | |
] | |
else: | |
vals_list = [ | |
{ | |
"product_id": sub_product.id, | |
"price": sub_product.list_price, | |
"quantity": 1, | |
} | |
for sub_product in sale_order_line.product_id.sub_products_ids | |
] | |
if vals_list: | |
curr_products = sub_product_line_wizard.create(vals_list) | |
line_values = [Command.link(product.id) for product in curr_products] | |
res.update({ | |
"sub_products_ids": line_values, | |
"sale_order_line_id": sale_order_line_id, | |
}) |
existing_lines.product_uom_qty = rec.quantity | ||
existing_lines.last_price = rec.price | ||
existing_lines.price_unit = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should make a database call.You can use the code below to reduce database calls.
existing_lines.product_uom_qty = rec.quantity | |
existing_lines.last_price = rec.price | |
existing_lines.price_unit = 0 | |
existing_lines.write({ | |
"product_uom_qty": rec.quantity, | |
"last_price": rec.price, | |
"price_unit": 0, | |
}) |
existing_lines = self.env["sale.order.line"].search( | ||
[ | ||
("main_product_line_id", "=", self.sale_order_line_id.id), | ||
("product_id", "=", rec.product_id.id), | ||
("order_id", "=", self.sale_order_line_id.order_id.id) | ||
], | ||
limit=1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use a search outside of the loop.
In this module, added the sub-products in specific products when
boolean is true, and by using the wizard, add all the sub-products in
sale.order.line, and also added the sub-products in the invoice, and
customer preview.
task-4907378