delivery_usability: Move code from stock_packaging_usability_pp to delivery_usability
I don't use stock_packaging_usability_pp from OCA/stock-logistics-tracking because the feature is native since v11 (I didn't figure it out when I ported stock_packaging_usability_ul from v10 to v14 under the new name stock_packaging_usability_ul I also improved the code to clean it up and use the native field for measured weight
This commit is contained in:
@@ -22,6 +22,7 @@ This module has been written by Alexis de Lattre from Akretion <alexis.delattre@
|
||||
'depends': ['delivery'],
|
||||
'data': [
|
||||
'views/stock_picking.xml',
|
||||
'views/product_packaging.xml',
|
||||
],
|
||||
'installable': True,
|
||||
}
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
from . import product_packaging
|
||||
from . import stock_picking
|
||||
from . import stock_move
|
||||
from . import stock_quant_package
|
||||
|
||||
31
delivery_usability/models/product_packaging.py
Normal file
31
delivery_usability/models/product_packaging.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# Copyright 2018-2021 Akretion (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ProductPackaging(models.Model):
|
||||
_inherit = 'product.packaging'
|
||||
|
||||
# product.packaging is defined in the 'product' module and enhanced in the 'delivery' module
|
||||
# I used to make the improvements on the datamodel of product.packaging in the OCA module
|
||||
# 'stock_packaging_usability_pp' from OCA/stock-logistics-tracking,
|
||||
# but I eventually figured out that the feature provided by 'stock_packaging_usability_pp'
|
||||
# was native in the 'delivery' module via the wizard choose.delivery.package.
|
||||
# So I stopped using 'stock_packaging_usability_pp' and I moved the datamodel changes
|
||||
# here in the module 'delivery_usability'
|
||||
name = fields.Char(translate=True)
|
||||
weight = fields.Float(digits="Stock Weight", string="Empty Package Weight")
|
||||
active = fields.Boolean(default=True)
|
||||
# packaging_type is important, in particular for pallets for which
|
||||
# we need a special implementation to enter the height
|
||||
packaging_type = fields.Selection(
|
||||
[
|
||||
("unit", "Unit"),
|
||||
("pack", "Pack"),
|
||||
("box", "Box"),
|
||||
("pallet", "Pallet"),
|
||||
],
|
||||
string="Type",
|
||||
)
|
||||
23
delivery_usability/models/stock_move.py
Normal file
23
delivery_usability/models/stock_move.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Copyright 2019 Akretion France (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class StockMove(models.Model):
|
||||
_inherit = "stock.move"
|
||||
|
||||
# Fixing bug https://github.com/odoo/odoo/issues/34702
|
||||
@api.depends("product_id", "product_uom_qty", "product_uom")
|
||||
def _cal_move_weight(self):
|
||||
weight_uom_categ = self.env.ref("uom.product_uom_categ_kgm")
|
||||
kg_uom = self.env.ref("uom.product_uom_kgm")
|
||||
for move in self:
|
||||
if move.product_id.uom_id.category_id == weight_uom_categ:
|
||||
move.weight = move.product_id.uom_id._compute_quantity(
|
||||
move.product_qty, kg_uom
|
||||
)
|
||||
else:
|
||||
move.weight = move.product_qty * move.product_id.weight
|
||||
68
delivery_usability/models/stock_quant_package.py
Normal file
68
delivery_usability/models/stock_quant_package.py
Normal file
@@ -0,0 +1,68 @@
|
||||
# Copyright 2019-2024 Akretion France (https://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
|
||||
from odoo import fields, models
|
||||
from odoo.tools import float_is_zero
|
||||
|
||||
|
||||
class StockQuantPackage(models.Model):
|
||||
_inherit = "stock.quant.package"
|
||||
|
||||
# These 2 fields are defined in the 'delivery' module but they forgot
|
||||
# the decimal precision
|
||||
shipping_weight = fields.Float(digits="Stock Weight")
|
||||
weight = fields.Float(digits="Stock Weight")
|
||||
|
||||
# Fixing bug https://github.com/odoo/odoo/issues/34702
|
||||
# and take into account the weight of the packaging
|
||||
# WARNING: this method _compute_weight() is also inherited by the OCA module
|
||||
# base_delivery_carrier_label so if you use that module, you should copy
|
||||
# that piece of code in a custom module that depend on delivery_usability
|
||||
# and base_delivery_carrier_label
|
||||
def _compute_weight(self):
|
||||
smlo = self.env["stock.move.line"]
|
||||
weight_uom_categ = self.env.ref("uom.product_uom_categ_kgm")
|
||||
kg_uom = self.env.ref("uom.product_uom_kgm")
|
||||
weight_prec = self.env['decimal.precision'].precision_get('Stock Weight')
|
||||
for package in self:
|
||||
# if the weight of the package has been measured,
|
||||
# it is written in shipping_weight
|
||||
if not float_is_zero(package.shipping_weight, precision_digits=weight_prec):
|
||||
weight = package.shipping_weight
|
||||
# otherwise, we compute the theorical weight from the weight of the products
|
||||
# and the weight of the packaging
|
||||
# Since Odoo v11, consu products don't create quants, so I can't loop
|
||||
# on pack.quant_ids to get all the items inside a package: I have to
|
||||
# get the picking, then loop on the stock.move.line of that picking
|
||||
# linked to that package
|
||||
else:
|
||||
weight = 0.0
|
||||
# the package can be seen in a return
|
||||
# So I get the picking of it's first appearance
|
||||
domain = [
|
||||
("result_package_id", "=", package.id),
|
||||
("product_id", "!=", False),
|
||||
]
|
||||
first_move_line = smlo.search(
|
||||
domain + [('picking_id', '!=', False)], limit=1, order='id')
|
||||
if first_move_line:
|
||||
picking_id = first_move_line.picking_id.id
|
||||
current_picking_move_line_ids = smlo.search(
|
||||
domain + [("picking_id", "=", picking_id)])
|
||||
for ml in current_picking_move_line_ids:
|
||||
if ml.product_uom_id.category_id == weight_uom_categ:
|
||||
weight += ml.product_uom_id._compute_quantity(
|
||||
ml.qty_done, kg_uom
|
||||
)
|
||||
else:
|
||||
weight += (
|
||||
ml.product_uom_id._compute_quantity(
|
||||
ml.qty_done, ml.product_id.uom_id
|
||||
)
|
||||
* ml.product_id.weight
|
||||
)
|
||||
if package.packaging_id:
|
||||
weight += package.packaging_id.weight
|
||||
package.weight = weight
|
||||
79
delivery_usability/views/product_packaging.xml
Normal file
79
delivery_usability/views/product_packaging.xml
Normal file
@@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!--
|
||||
Copyright 2019-2024 Akretion France (http://www.akretion.com/)
|
||||
@author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
<odoo>
|
||||
|
||||
|
||||
<!-- I don't know why the form view of product.packaging in the delivery
|
||||
module has "<field name="inherit_id" eval="False"/>"
|
||||
instead of a standard inherit of product.product_packaging_form_view -->
|
||||
<record id="product_packaging_delivery_form" model="ir.ui.view">
|
||||
<field name="name">stock_packaging_usability_pp.product.packaging.form</field>
|
||||
<field name="model">product.packaging</field>
|
||||
<field name="inherit_id" ref="delivery.product_packaging_delivery_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="package_carrier_type" position="after">
|
||||
<field name="packaging_type" />
|
||||
<field name="active" invisible="1" />
|
||||
</field>
|
||||
<label for="max_weight" position="before">
|
||||
<label for="weight" />
|
||||
<div class="o_row" name="weight">
|
||||
<field name="weight" />
|
||||
<span><field name="weight_uom_name" /></span>
|
||||
</div>
|
||||
</label>
|
||||
<label for="name" position="before">
|
||||
<widget
|
||||
name="web_ribbon"
|
||||
title="Archived"
|
||||
bg_color="bg-danger"
|
||||
attrs="{'invisible': [('active', '=', True)]}"
|
||||
/>
|
||||
</label>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="product_packaging_delivery_tree" model="ir.ui.view">
|
||||
<field name="name">stock_packaging_usability_pp.product.packaging.tree</field>
|
||||
<field name="model">product.packaging</field>
|
||||
<field name="inherit_id" ref="delivery.product_packaging_delivery_tree" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="name" position="after">
|
||||
<field name="packaging_type" optional="show" />
|
||||
</field>
|
||||
<field name="max_weight" position="before">
|
||||
<field name="weight" optional="show" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- There is no native serch view for product.packaging -->
|
||||
<record id="product_packaging_search" model="ir.ui.view">
|
||||
<field name="name">product.packaging.search</field>
|
||||
<field name="model">product.packaging</field>
|
||||
<field name="arch" type="xml">
|
||||
<search>
|
||||
<field name="name" />
|
||||
<separator />
|
||||
<filter
|
||||
string="Archived"
|
||||
name="inactive"
|
||||
domain="[('active', '=', False)]"
|
||||
/>
|
||||
<group name="groupby">
|
||||
<filter
|
||||
name="packaging_type_groupby"
|
||||
string="Packaging Type"
|
||||
context="{'group_by': 'packaging_type'}"
|
||||
/>
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user