Comments (3)
The module is not prepared for nesting product packs. If you want, you can contribute with:
- Adding such comment on the ROADMAP of the module.
- Also adding a domain to prevent to select product packs on the pack lines.
- Or making this to work.
from product-pack.
Here is what i did to be able to duplicate them without creating new lines and keeping the link between the componants and pack_parent_line_id.
I suppose that we can do it better
`
from odoo import api, models, fields
class SaleOrder(models.Model):
_inherit = "sale.order"
#I need this field in the sale order to avoid them create lines of composants in the expand_pack_line method when i duplicate one order
is_copy = fields.Boolean("Is a copy")
def _reset_sequence_before_copy(self):
'''I need this method to deduplicate lines that have the same sequence in my order before i duplicate it (from module sale_order_line_sequence)'''
for rec in self:
current_sequence = 1
for line in sorted(rec.order_line, key=lambda x: (x.sequence, x.id)):
if line.sequence != current_sequence:
line.sequence = current_sequence
current_sequence += 1
def copy(self, default=None):
#I deduplicate the sequences of the order lines because i will use it to identify and link the new lines to the original lines
self._reset_sequence_before_copy()
#I am using the field is_copy to avoid creating new line of pack when a pack is a copy from another pack
if default:
default['is_copy']=True
else:
default={'is_copy':True}
sale_copy = super(SaleOrder, self).copy(default)
#Delete the componants products because we are going to recopy them
sale_copy.order_line.filtered(lambda l: l.pack_parent_line_id).unlink()
#I copy the sequence number of the original line to keep the same sequence order
for lines in sale_copy.order_line:
lines.copied_sale_line_id = self.order_line.filtered(lambda r:r.sequence == lines.sequence and r.product_id.id == lines.product_id.id).id
#search all the lines that have been deleted by the sale_product_pack module
lines_to_copy_from_old = self.order_line.filtered(
lambda l: l.pack_parent_line_id
)
#Copy them into the new order with the link to the original line and with its sequence
for line in lines_to_copy_from_old:
line.copy(default={'order_id': sale_copy.id,
'copied_sale_line_id': line.id,
'sequence': line.sequence})
#Select all the lines that are liked to componants lines in the the order
new_pack_lines = sale_copy.order_line.filtered(lambda r: r.copied_sale_line_id.pack_child_line_ids)
#Modify field pack_parent_line_id of the componants that have been duplicated
for new_pack_line in new_pack_lines:
lines_to_link_to_current_pack = sale_copy.order_line.filtered(lambda r: r.id in new_pack_line.copied_sale_line_id.pack_child_line_ids.ids)
lines_to_link_to_current_pack.write({'pack_parent_line_id': new_pack_line.id})
#Disable the field is_copy so that we can add the pack products and allow it to add the componants lines
sale_copy.is_copy=False
return sale_copy
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
def expand_pack_line(self, write=False):
if not self.order_id.is_copy:
super(SaleOrderLine, self).expand_pack_line(write)
copied_sale_line_id = fields.Many2one(
"sale.order.line",
"Copied sale_line_id",
help="The copied sale_line_id.",
)
`
from product-pack.
There hasn't been any activity on this issue in the past 6 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this issue to never become stale, please ask a PSC member to apply the "no stale" label.
from product-pack.
Related Issues (20)
- [sale_product_pack] can't update quantity when sale is not draft HOT 3
- Migration to version 14.0 HOT 16
- The package price is calculated twice in the online shop HOT 1
- Poduct Pack no compatible with e-commerce HOT 1
- The FATHER product of the pack leaves it pending HOT 2
- Migration to version 15.0 HOT 1
- Add product pack app HOT 20
- i installed the 2 app but delivery stop at validate HOT 2
- POS: Manage product packs HOT 2
- {14}mig sale_stock_product_pack HOT 1
- Pack product not reserved when storable HOT 7
- Automatic backorder calculation HOT 1
- Pack component price changes on price update HOT 1
- The price is doubled in cart with website_sale_product_pack HOT 1
- Migration to version 16.0 HOT 1
- Need a module for pos HOT 1
- The prices on the sale quotation are incorrect when changing the price list with a different currency HOT 2
- Migration to version 17.0 HOT 5
- Packs "Totalized in main product" and "Non Detailed" don't include product list price HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from product-pack.