[IMP] sale_order_batch: restructure batch product
This commit is contained in:
parent
e18185e617
commit
cade3b897a
8 changed files with 41 additions and 31 deletions
4
.vscode/launch.json
vendored
4
.vscode/launch.json
vendored
|
|
@ -13,8 +13,8 @@
|
||||||
"--addons-path=${config:odoo.addons_path},${workspaceFolder}",
|
"--addons-path=${config:odoo.addons_path},${workspaceFolder}",
|
||||||
"--limit-time-real=0",
|
"--limit-time-real=0",
|
||||||
"--limit-time-cpu=0",
|
"--limit-time-cpu=0",
|
||||||
// "--init=stock",
|
// "--init=sale_management,sale_order_batch",
|
||||||
"--update=sale_order_batch,sale_order_batch_stock",
|
"--update=sale_order_batch",
|
||||||
"--dev=xml"
|
"--dev=xml"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ Changelog
|
||||||
:1.0.1: rename product creation methode
|
:1.0.1: rename product creation methode
|
||||||
:1.1.0: Make validity_date persistent, add batches to SO views
|
:1.1.0: Make validity_date persistent, add batches to SO views
|
||||||
:1.1.1: Remove validity date
|
:1.1.1: Remove validity date
|
||||||
|
:2.0.0: Move product logic to sale order lines
|
||||||
|
|
||||||
Bug Tracker
|
Bug Tracker
|
||||||
===========
|
===========
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
"author": "BAKEUP",
|
"author": "BAKEUP",
|
||||||
"website": "https://www.bakeup.org",
|
"website": "https://www.bakeup.org",
|
||||||
"category": "Sale",
|
"category": "Sale",
|
||||||
"version": "16.0.1.1.1",
|
"version": "16.0.2.0.0",
|
||||||
"depends": ["sale", "product"],
|
"depends": ["sale", "product"],
|
||||||
"data": [
|
"data": [
|
||||||
"data/ir_sequence_data.xml",
|
"data/ir_sequence_data.xml",
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,3 @@ class SaleOrderBatchProduct(models.Model):
|
||||||
def _compute_product_packaging_qty(self):
|
def _compute_product_packaging_qty(self):
|
||||||
for product in self:
|
for product in self:
|
||||||
product.product_packaging_qty = product.product_packaging_id.qty if product.product_packaging_id else 1
|
product.product_packaging_qty = product.product_packaging_id.qty if product.product_packaging_id else 1
|
||||||
|
|
||||||
def unlink(self):
|
|
||||||
for product in self:
|
|
||||||
if not product.sale_order_line_ids:
|
|
||||||
return super().unlink()
|
|
||||||
return True
|
|
||||||
|
|
|
||||||
|
|
@ -7,31 +7,44 @@ class SaleOrderLine(models.Model):
|
||||||
batch_id = fields.Many2one(related="order_id.batch_id")
|
batch_id = fields.Many2one(related="order_id.batch_id")
|
||||||
batch_product_id = fields.Many2one("sale.order.batch.product")
|
batch_product_id = fields.Many2one("sale.order.batch.product")
|
||||||
|
|
||||||
# TODO:
|
def _link_batch_product(self):
|
||||||
# - recompute values on batchproduct
|
lines_with_batch = self.filtered(lambda l: l.batch_id)
|
||||||
# - check for last item on unlink or removal ob batch_id and remove batch_product_id
|
for line in lines_with_batch:
|
||||||
def _update_batch_product(self):
|
|
||||||
for line in self:
|
|
||||||
batch_id = line.batch_id
|
batch_id = line.batch_id
|
||||||
if batch_id:
|
batch_product = self.env["sale.order.batch.product"].search(
|
||||||
batch_product = line.env["sale.order.batch.product"].search(
|
[("product_id", "=", line.product_id.id), ("batch_id", "=", batch_id.id)], limit=1
|
||||||
[("product_id", "=", line.product_id.id), ("batch_id", "=", batch_id.id)], limit=1
|
)
|
||||||
|
if not batch_product:
|
||||||
|
batch_product = self.env["sale.order.batch.product"].create(
|
||||||
|
{"batch_id": batch_id.id, "product_id": line.product_id.id}
|
||||||
)
|
)
|
||||||
if not batch_product:
|
line.batch_product_id = batch_product
|
||||||
batch_product = line.env["sale.order.batch.product"].create(
|
|
||||||
{"batch_id": batch_id.id, "product_id": line.product_id.id}
|
def _unlink_batch_product(self):
|
||||||
)
|
lines_to_unlink = self.filtered(lambda l: l.batch_product_id)
|
||||||
line.batch_product_id = batch_product
|
batch_product_unlink = self.env["sale.order.batch.product"]
|
||||||
else:
|
for line in lines_to_unlink:
|
||||||
line.batch_product_id.unlink()
|
if line.batch_product_id:
|
||||||
line.batch_product_id = False
|
batch_product = line.batch_product_id
|
||||||
|
if len(batch_product.sale_order_line_ids) == 1:
|
||||||
|
batch_product_unlink += batch_product
|
||||||
|
else:
|
||||||
|
line.batch_product_id = False
|
||||||
|
batch_product_unlink.unlink()
|
||||||
|
|
||||||
|
def _update_batch_product(self):
|
||||||
|
lines_with_batch = self.filtered(lambda l: l.batch_id)
|
||||||
|
lines_without_batch = self - lines_with_batch
|
||||||
|
lines_with_batch.filtered(
|
||||||
|
lambda l: l.batch_product_id and l.batch_product_id.product_id != l.product_id
|
||||||
|
)._unlink_batch_product()
|
||||||
|
lines_with_batch._link_batch_product()
|
||||||
|
lines_without_batch._unlink_batch_product()
|
||||||
|
|
||||||
@api.model_create_multi
|
@api.model_create_multi
|
||||||
def create(self, vals_list):
|
def create(self, vals_list):
|
||||||
res = super().create(vals_list)
|
res = super().create(vals_list)
|
||||||
for line in res:
|
res._link_batch_product()
|
||||||
if line.batch_id:
|
|
||||||
line._update_batch_product()
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def write(self, vals):
|
def write(self, vals):
|
||||||
|
|
@ -41,7 +54,5 @@ class SaleOrderLine(models.Model):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def unlink(self):
|
def unlink(self):
|
||||||
for line in self:
|
self._unlink_batch_product()
|
||||||
if line.batch_product_id:
|
|
||||||
line.batch_product_id.unlink()
|
|
||||||
return super().unlink()
|
return super().unlink()
|
||||||
|
|
|
||||||
|
|
@ -3,3 +3,4 @@
|
||||||
:1.0.1: rename product creation methode
|
:1.0.1: rename product creation methode
|
||||||
:1.1.0: Make validity_date persistent, add batches to SO views
|
:1.1.0: Make validity_date persistent, add batches to SO views
|
||||||
:1.1.1: Remove validity date
|
:1.1.1: Remove validity date
|
||||||
|
:2.0.0: Move product logic to sale order lines
|
||||||
|
|
|
||||||
|
|
@ -402,6 +402,8 @@ anymore as log as they are part of a batch. Only Sale Orders in state Qutotation
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="field"><th class="field-name">1.1.1:</th><td class="field-body">Remove validity date</td>
|
<tr class="field"><th class="field-name">1.1.1:</th><td class="field-body">Remove validity date</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr class="field"><th class="field-name">2.0.0:</th><td class="field-body">Move product logic to sale order lines</td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@
|
||||||
<field name="sale_order_line_ids" widget="section_and_note_one2many">
|
<field name="sale_order_line_ids" widget="section_and_note_one2many">
|
||||||
<tree editable="bottom" create="0">
|
<tree editable="bottom" create="0">
|
||||||
<field name="sequence" widget="handle"/>
|
<field name="sequence" widget="handle"/>
|
||||||
|
<field name="order_id"/>
|
||||||
<field name="name"/>
|
<field name="name"/>
|
||||||
<field name="order_partner_id"/>
|
<field name="order_partner_id"/>
|
||||||
<field name="product_uom_qty"/>
|
<field name="product_uom_qty"/>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue