mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[12.0][MIG] stock_secondary_unit
This commit is contained in:
@@ -14,13 +14,13 @@ Stock Secondary Unit
|
||||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||
:alt: License: AGPL-3
|
||||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github
|
||||
:target: https://github.com/OCA/stock-logistics-warehouse/tree/11.0/stock_secondary_unit
|
||||
:target: https://github.com/OCA/stock-logistics-warehouse/tree/12.0/stock_secondary_unit
|
||||
:alt: OCA/stock-logistics-warehouse
|
||||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
|
||||
:target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-11-0/stock-logistics-warehouse-11-0-stock_secondary_unit
|
||||
:target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-12-0/stock-logistics-warehouse-12-0-stock_secondary_unit
|
||||
:alt: Translate me on Weblate
|
||||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
|
||||
:target: https://runbot.odoo-community.org/runbot/153/11.0
|
||||
:target: https://runbot.odoo-community.org/runbot/153/12.0
|
||||
:alt: Try me on Runbot
|
||||
|
||||
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||
@@ -51,7 +51,7 @@ Bug Tracker
|
||||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-warehouse/issues>`_.
|
||||
In case of trouble, please check there if your issue has already been reported.
|
||||
If you spotted it first, help us smashing it by providing a detailed and welcomed
|
||||
`feedback <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_secondary_unit%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||
`feedback <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_secondary_unit%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||
|
||||
Do not contact contributors directly about support or help with technical issues.
|
||||
|
||||
@@ -68,6 +68,7 @@ Contributors
|
||||
|
||||
* Carlos Dauden <carlos.dauden@tecnativa.com>
|
||||
* Sergio Teruel <sergio.teruel@tecnativa.com>
|
||||
* Kitti Upariphutthiphong <kittiu@ecosoft.co.th>
|
||||
|
||||
Maintainers
|
||||
~~~~~~~~~~~
|
||||
@@ -82,6 +83,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||
mission is to support the collaborative development of Odoo features and
|
||||
promote its widespread use.
|
||||
|
||||
This module is part of the `OCA/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/11.0/stock_secondary_unit>`_ project on GitHub.
|
||||
This module is part of the `OCA/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/12.0/stock_secondary_unit>`_ project on GitHub.
|
||||
|
||||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
{
|
||||
'name': 'Stock Secondary Unit',
|
||||
'summary': 'Get product quantities in a secondary unit',
|
||||
'version': '11.0.1.0.0',
|
||||
'version': '12.0.1.0.0',
|
||||
'development_status': 'Beta',
|
||||
'category': 'stock',
|
||||
'website': 'https://github.com/OCA/stock-logistics-warehouse',
|
||||
|
||||
@@ -7,6 +7,7 @@ from odoo.tools.float_utils import float_round
|
||||
|
||||
class StockProductSecondaryUnit(models.AbstractModel):
|
||||
_name = 'stock.product.secondary.unit'
|
||||
_description = 'Stock Product Secondary Unit'
|
||||
|
||||
secondary_unit_qty_available = fields.Float(
|
||||
string='Quantity On Hand (2Unit)',
|
||||
|
||||
@@ -7,6 +7,7 @@ from odoo.tools.float_utils import float_round
|
||||
|
||||
class StockSecondaryUnitMixin(models.AbstractModel):
|
||||
_name = 'stock.secondary.unit.mixin'
|
||||
_description = 'Stock Secondary Unit Mixin'
|
||||
|
||||
secondary_uom_id = fields.Many2one(
|
||||
comodel_name='product.secondary.unit',
|
||||
@@ -36,7 +37,7 @@ class StockMoveLine(models.Model):
|
||||
def create(self, vals):
|
||||
move = self.env['stock.move'].browse(vals['move_id'])
|
||||
if move.secondary_uom_id:
|
||||
uom = self.env['product.uom'].browse(vals['product_uom_id'])
|
||||
uom = self.env['uom.uom'].browse(vals['product_uom_id'])
|
||||
factor = move.secondary_uom_id.factor * uom.factor
|
||||
move_line_qty = vals.get(
|
||||
'product_uom_qty', vals.get('qty_done', 0.0))
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
* Carlos Dauden <carlos.dauden@tecnativa.com>
|
||||
* Sergio Teruel <sergio.teruel@tecnativa.com>
|
||||
* Kitti Upariphutthiphong <kittiu@ecosoft.co.th>
|
||||
|
||||
@@ -367,7 +367,7 @@ ul.auto-toc {
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/11.0/stock_secondary_unit"><img alt="OCA/stock-logistics-warehouse" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/stock-logistics-warehouse-11-0/stock-logistics-warehouse-11-0-stock_secondary_unit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/153/11.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
|
||||
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/12.0/stock_secondary_unit"><img alt="OCA/stock-logistics-warehouse" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/stock-logistics-warehouse-12-0/stock-logistics-warehouse-12-0-stock_secondary_unit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/153/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
|
||||
<p>This module extends the functionality of stock module to allow define
|
||||
other units with their conversion factor.</p>
|
||||
<p><strong>Table of contents</strong></p>
|
||||
@@ -400,7 +400,7 @@ other units with their conversion factor.</p>
|
||||
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/issues">GitHub Issues</a>.
|
||||
In case of trouble, please check there if your issue has already been reported.
|
||||
If you spotted it first, help us smashing it by providing a detailed and welcomed
|
||||
<a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_secondary_unit%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
|
||||
<a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_secondary_unit%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
|
||||
<p>Do not contact contributors directly about support or help with technical issues.</p>
|
||||
</div>
|
||||
<div class="section" id="credits">
|
||||
@@ -416,6 +416,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
|
||||
<ul class="simple">
|
||||
<li>Carlos Dauden <<a class="reference external" href="mailto:carlos.dauden@tecnativa.com">carlos.dauden@tecnativa.com</a>></li>
|
||||
<li>Sergio Teruel <<a class="reference external" href="mailto:sergio.teruel@tecnativa.com">sergio.teruel@tecnativa.com</a>></li>
|
||||
<li>Kitti Upariphutthiphong <<a class="reference external" href="mailto:kittiu@ecosoft.co.th">kittiu@ecosoft.co.th</a>></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="maintainers">
|
||||
@@ -425,7 +426,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
|
||||
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||
mission is to support the collaborative development of Odoo features and
|
||||
promote its widespread use.</p>
|
||||
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/11.0/stock_secondary_unit">OCA/stock-logistics-warehouse</a> project on GitHub.</p>
|
||||
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/12.0/stock_secondary_unit">OCA/stock-logistics-warehouse</a> project on GitHub.</p>
|
||||
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -11,8 +11,8 @@ class TestProductSecondaryUnit(SavepointCase):
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.warehouse = cls.env.ref('stock.warehouse0')
|
||||
cls.product_uom_kg = cls.env.ref('product.product_uom_kgm')
|
||||
cls.product_uom_unit = cls.env.ref('product.product_uom_unit')
|
||||
cls.product_uom_kg = cls.env.ref('uom.product_uom_kgm')
|
||||
cls.product_uom_unit = cls.env.ref('uom.product_uom_unit')
|
||||
ProductAttribute = cls.env['product.attribute']
|
||||
ProductAttributeValue = cls.env['product.attribute.value']
|
||||
cls.attribute_color = ProductAttribute.create({'name': 'test_color'})
|
||||
@@ -24,7 +24,6 @@ class TestProductSecondaryUnit(SavepointCase):
|
||||
'name': 'test_black',
|
||||
'attribute_id': cls.attribute_color.id,
|
||||
})
|
||||
Product = cls.env['product.product']
|
||||
cls.product_template = cls.env['product.template'].create({
|
||||
'name': 'test',
|
||||
'uom_id': cls.product_uom_kg.id,
|
||||
@@ -46,16 +45,10 @@ class TestProductSecondaryUnit(SavepointCase):
|
||||
],
|
||||
'attribute_line_ids': [(0, 0, {
|
||||
'attribute_id': cls.attribute_color.id,
|
||||
'value_ids': [(4, cls.attribute_value_white.id),
|
||||
(4, cls.attribute_value_black.id)],
|
||||
})],
|
||||
})
|
||||
cls.product_white = Product.create({
|
||||
'product_tmpl_id': cls.product_template.id,
|
||||
'attribute_value_ids': [(6, 0, [cls.attribute_value_white.id])],
|
||||
})
|
||||
cls.product_black = Product.create({
|
||||
'product_tmpl_id': cls.product_template.id,
|
||||
'attribute_value_ids': [(6, 0, [cls.attribute_value_black.id])],
|
||||
})
|
||||
secondary_unit = cls.env['product.secondary.unit'].search([
|
||||
('product_tmpl_id', '=', cls.product_template.id),
|
||||
], limit=1)
|
||||
@@ -65,21 +58,55 @@ class TestProductSecondaryUnit(SavepointCase):
|
||||
})
|
||||
StockQuant = cls.env['stock.quant']
|
||||
cls.quant_white = StockQuant.create({
|
||||
'product_id': cls.product_white.id,
|
||||
'product_id': cls.product_template.product_variant_ids[0].id,
|
||||
'location_id': cls.warehouse.lot_stock_id.id,
|
||||
'quantity': 10.0,
|
||||
})
|
||||
cls.quant_black = StockQuant.create({
|
||||
'product_id': cls.product_black.id,
|
||||
'product_id': cls.product_template.product_variant_ids[1].id,
|
||||
'location_id': cls.warehouse.lot_stock_id.id,
|
||||
'quantity': 10.0,
|
||||
})
|
||||
|
||||
def test_stock_secondary_unit_template(self):
|
||||
def test_01_stock_secondary_unit_template(self):
|
||||
self.assertEqual(
|
||||
self.product_template.secondary_unit_qty_available, 40.0)
|
||||
|
||||
def test_stock_secondary_unit_variant(self):
|
||||
def test_02_stock_secondary_unit_variant(self):
|
||||
for variant in self.product_template.product_variant_ids.filtered(
|
||||
'attribute_value_ids'):
|
||||
self.assertEqual(variant.secondary_unit_qty_available, 20)
|
||||
|
||||
def test_03_stock_picking_secondary_unit(self):
|
||||
StockPicking = self.env['stock.picking']
|
||||
product1 = self.product_template.product_variant_ids[0]
|
||||
location = self.env.ref('stock.stock_location_suppliers')
|
||||
location_dest = self.env.ref('stock.stock_location_stock')
|
||||
picking_type = self.env.ref('stock.picking_type_in')
|
||||
move_vals = {
|
||||
'product_id': product1.id,
|
||||
'name': product1.display_name,
|
||||
'secondary_uom_id': product1.secondary_uom_ids[0].id,
|
||||
'product_uom': product1.uom_id.id,
|
||||
'product_uom_qty': 10.0,
|
||||
'location_id': location.id,
|
||||
'location_dest_id': location_dest.id,
|
||||
}
|
||||
do_vals = {
|
||||
'location_id': location.id,
|
||||
'location_dest_id': location_dest.id,
|
||||
'picking_type_id': picking_type.id,
|
||||
'move_ids_without_package': [(0, None, move_vals),
|
||||
(0, None, move_vals)], # 2 moves
|
||||
}
|
||||
delivery_order = StockPicking.create(do_vals)
|
||||
delivery_order.action_confirm()
|
||||
# Move is merged into 1 line for both stock.move and stock.move.line
|
||||
self.assertEquals(len(delivery_order.move_lines), 1)
|
||||
self.assertEquals(len(delivery_order.move_line_ids), 1)
|
||||
# Qty merged to 20, and secondary unit qty is 40line
|
||||
uom_qty = sum(delivery_order.move_lines.mapped('product_uom_qty'))
|
||||
secondary_uom_qty = \
|
||||
sum(delivery_order.move_line_ids.mapped('secondary_uom_qty'))
|
||||
self.assertEquals(uom_qty, 20.0)
|
||||
self.assertEquals(secondary_uom_qty, 40.0)
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<field name="name">Product template Secondary Unit</field>
|
||||
<field name="model">product.template</field>
|
||||
<field name="inherit_id" ref="stock.view_template_property_form"/>
|
||||
<field name="groups_id" eval="[(4, ref('product.group_uom'))]"/>
|
||||
<field name="groups_id" eval="[(4, ref('uom.group_uom'))]"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//group[@name='inventory']" position="inside">
|
||||
<group string="Secondary unit">
|
||||
@@ -23,7 +23,7 @@
|
||||
<field name="model">product.template</field>
|
||||
<field name="inherit_id"
|
||||
ref="stock.product_template_form_view_procurement_button"/>
|
||||
<field name="groups_id" eval="[(4, ref('product.group_uom'))]"/>
|
||||
<field name="groups_id" eval="[(4, ref('uom.group_uom'))]"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//button[@name='action_open_quants']" position="after">
|
||||
<button type="object"
|
||||
@@ -43,7 +43,7 @@
|
||||
<field name="model">product.product</field>
|
||||
<field name="inherit_id"
|
||||
ref="stock.product_form_view_procurement_button"/>
|
||||
<field name="groups_id" eval="[(4, ref('product.group_uom'))]"/>
|
||||
<field name="groups_id" eval="[(4, ref('uom.group_uom'))]"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='qty_available']/.." position="after">
|
||||
<button class="oe_stat_button"
|
||||
@@ -62,7 +62,7 @@
|
||||
<record id="product_template_tree_view" model="ir.ui.view">
|
||||
<field name="model">product.template</field>
|
||||
<field name="inherit_id" ref="product.product_template_tree_view"/>
|
||||
<field name="groups_id" eval="[(4, ref('product.group_uom'))]"/>
|
||||
<field name="groups_id" eval="[(4, ref('uom.group_uom'))]"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='uom_id']" position="after">
|
||||
<field name="secondary_unit_qty_available"/>
|
||||
@@ -74,7 +74,7 @@
|
||||
<record id="product_product_tree_view" model="ir.ui.view">
|
||||
<field name="model">product.product</field>
|
||||
<field name="inherit_id" ref="product.product_product_tree_view"/>
|
||||
<field name="groups_id" eval="[(4, ref('product.group_uom'))]"/>
|
||||
<field name="groups_id" eval="[(4, ref('uom.group_uom'))]"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='uom_id']" position="after">
|
||||
<field name="secondary_unit_qty_available"/>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<field name="name">Stock Move Secondary Unit</field>
|
||||
<field name="model">stock.move.line</field>
|
||||
<field name="inherit_id" ref="stock.view_stock_move_line_operation_tree"/>
|
||||
<field name="groups_id" eval="[(4, ref('product.group_uom'))]"/>
|
||||
<field name="groups_id" eval="[(4, ref('uom.group_uom'))]"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="product_uom_qty" position="before">
|
||||
<field name="secondary_uom_qty"/>
|
||||
|
||||
@@ -7,15 +7,15 @@
|
||||
<field name="name">Stock Picking Secondary Unit</field>
|
||||
<field name="model">stock.picking</field>
|
||||
<field name="inherit_id" ref="stock.view_picking_form"/>
|
||||
<field name="groups_id" eval="[(4, ref('product.group_uom'))]"/>
|
||||
<field name="groups_id" eval="[(4, ref('uom.group_uom'))]"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='move_lines']/tree/field[@name='product_uom_qty']" position="before">
|
||||
<xpath expr="//field[@name='move_ids_without_package']/tree/field[@name='product_uom_qty']" position="before">
|
||||
<field name="secondary_uom_qty"/>
|
||||
<field name="secondary_uom_id"
|
||||
domain="[('product_tmpl_id.product_variant_ids', 'in', [product_id])]"
|
||||
options="{'no_create': True}"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='move_line_ids']/tree/field[@name='product_uom_qty']" position="before">
|
||||
<xpath expr="//field[@name='move_line_ids_without_package']/tree/field[@name='product_uom_qty']" position="before">
|
||||
<field name="secondary_uom_qty"/>
|
||||
<field name="secondary_uom_id"
|
||||
domain="[('product_tmpl_id.product_variant_ids', 'in', [product_id])]"
|
||||
|
||||
Reference in New Issue
Block a user