Skip to content

Commit

Permalink
Merge pull request OCA#477 from Tecnativa/11.0-PR-stock_secondary_unit
Browse files Browse the repository at this point in the history
[11.0][NEW] stock_secondary_unit: New module for get stock in a secondary unit
  • Loading branch information
pedrobaeza authored Feb 16, 2019
2 parents 174e5ab + 3f72a91 commit d84776c
Show file tree
Hide file tree
Showing 19 changed files with 572 additions and 0 deletions.
1 change: 1 addition & 0 deletions oca_dependencies.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# list the OCA project dependencies, one per line
# add a github url if you need a forked version
product-attribute
purchase-workflow
web
server-ux
Expand Down
87 changes: 87 additions & 0 deletions stock_secondary_unit/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
====================
Stock Secondary Unit
====================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
: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
: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
: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
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the functionality of stock module to allow define
other units with their conversion factor.

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module you need to:

#. Go to a *Product > General Information tab*.
#. Create any record in "Secondary unit of measure".
#. Set the conversion factor.
#. Go to *Inventory tab* and set a second unit of measure.
#. Push button 'Quantity on hand' and set quantities in stock for this product.
#. Go to product list and you can see the secondary unit value.

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**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Tecnativa

Contributors
~~~~~~~~~~~~

* Carlos Dauden <[email protected]>
* Sergio Teruel <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions stock_secondary_unit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import models
24 changes: 24 additions & 0 deletions stock_secondary_unit/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2018 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
'name': 'Stock Secondary Unit',
'summary': 'Get product quantities in a secondary unit',
'version': '11.0.1.0.0',
'development_status': 'Beta',
'category': 'stock',
'website': 'https://github.com/OCA/stock-logistics-warehouse',
'author': 'Tecnativa, Odoo Community Association (OCA)',
'license': 'AGPL-3',
'application': False,
'installable': True,
'depends': [
'sale_stock',
'product_secondary_unit',
],
'data': [
'views/product_views.xml',
'views/stock_move_views.xml',
'views/stock_picking_views.xml',
'report/report_deliveryslip.xml',
],
}
75 changes: 75 additions & 0 deletions stock_secondary_unit/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_secondary_unit
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-09-11 06:27+0000\n"
"PO-Revision-Date: 2018-09-11 08:28+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: es_ES\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 2.0.6\n"

#. module: stock_secondary_unit
#: model:ir.model.fields,field_description:stock_secondary_unit.field_stock_product_secondary_unit_display_name
msgid "Display Name"
msgstr "Mostrar Nombre"

#. module: stock_secondary_unit
#: model:ir.model.fields,field_description:stock_secondary_unit.field_stock_product_secondary_unit_id
msgid "ID"
msgstr "ID"

#. module: stock_secondary_unit
#: model:ir.model.fields,field_description:stock_secondary_unit.field_stock_product_secondary_unit___last_update
msgid "Last Modified on"
msgstr "Última modificación en"

#. module: stock_secondary_unit
#: model:ir.ui.view,arch_db:stock_secondary_unit.product_form_view_procurement_button
#: model:ir.ui.view,arch_db:stock_secondary_unit.product_template_form_view_procurement_button
msgid "On Hand (2unit)"
msgstr "A mano (2Ud.)"

#. module: stock_secondary_unit
#: model:ir.model,name:stock_secondary_unit.model_product_product
msgid "Product"
msgstr "Producto"

#. module: stock_secondary_unit
#: model:ir.model,name:stock_secondary_unit.model_product_template
msgid "Product Template"
msgstr "Plantilla de producto"

#. module: stock_secondary_unit
#: model:ir.model.fields,field_description:stock_secondary_unit.field_product_product_secondary_unit_qty_available
#: model:ir.model.fields,field_description:stock_secondary_unit.field_product_template_secondary_unit_qty_available
#: model:ir.model.fields,field_description:stock_secondary_unit.field_stock_product_secondary_unit_secondary_unit_qty_available
msgid "Quantity On Hand (2Unit)"
msgstr "Cantidad a mano (2Ud.)"

#. module: stock_secondary_unit
#: model:ir.model.fields,field_description:stock_secondary_unit.field_product_product_stock_secondary_uom_id
#: model:ir.model.fields,field_description:stock_secondary_unit.field_product_template_stock_secondary_uom_id
msgid "Second unit for inventory"
msgstr "Segunda unidad de medida para inventario"

#. module: stock_secondary_unit
#: model:ir.ui.view,arch_db:stock_secondary_unit.view_template_property_form
msgid "Secondary unit"
msgstr "Unidad Secundaria"

#. module: stock_secondary_unit
#: model:ir.model,name:stock_secondary_unit.model_stock_product_secondary_unit
msgid "stock.product.secondary.unit"
msgstr ""

#~ msgid "Second Unit Quantity On Hand"
#~ msgstr "Segunda unidad de medida por defecto"
4 changes: 4 additions & 0 deletions stock_secondary_unit/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import procurement_rule
from . import product
from . import stock_move
23 changes: 23 additions & 0 deletions stock_secondary_unit/models/procurement_rule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2018 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models


class ProcurementRule(models.Model):
_inherit = 'procurement.rule'

def _get_stock_move_values(self, product_id, product_qty, product_uom,
location_id, name, origin, values, group_id):
res = super(ProcurementRule, self)._get_stock_move_values(
product_id, product_qty, product_uom, location_id, name, origin,
values, group_id
)
if values.get('sale_line_id', False):
sale_line = self.env['sale.order.line'].browse(
values['sale_line_id'])
if sale_line.secondary_uom_id:
res.update({
'secondary_uom_id': sale_line.secondary_uom_id.id,
'secondary_uom_qty': sale_line.secondary_uom_qty,
})
return res
45 changes: 45 additions & 0 deletions stock_secondary_unit/models/product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2018 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
from odoo.addons import decimal_precision as dp
from odoo.tools.float_utils import float_round


class StockProductSecondaryUnit(models.AbstractModel):
_name = 'stock.product.secondary.unit'

secondary_unit_qty_available = fields.Float(
string='Quantity On Hand (2Unit)',
compute='_compute_secondary_unit_qty_available',
digits=dp.get_precision('Product Unit of Measure'),
)

def _compute_secondary_unit_qty_available(self):
for product in self.filtered('stock_secondary_uom_id'):
qty = product.qty_available / (
product.stock_secondary_uom_id.factor or 1.0)
product.secondary_unit_qty_available = float_round(
qty, precision_rounding=product.uom_id.rounding)


class ProductTemplate(models.Model):
_inherit = ['product.template', 'stock.product.secondary.unit']
_name = 'product.template'

stock_secondary_uom_id = fields.Many2one(
comodel_name='product.secondary.unit',
string='Second unit for inventory',
)

def _compute_quantities(self):
super()._compute_quantities()
self._compute_secondary_unit_qty_available()


class ProductProduct(models.Model):
_inherit = ['product.product', 'stock.product.secondary.unit']
_name = 'product.product'

def _compute_quantities(self):
super()._compute_quantities()
self._compute_secondary_unit_qty_available()
51 changes: 51 additions & 0 deletions stock_secondary_unit/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2018 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
from odoo.addons import decimal_precision as dp
from odoo.tools.float_utils import float_round


class StockSecondaryUnitMixin(models.AbstractModel):
_name = 'stock.secondary.unit.mixin'

secondary_uom_id = fields.Many2one(
comodel_name='product.secondary.unit',
string='Second unit',
)
secondary_uom_qty = fields.Float(
string='Secondary Qty',
digits=dp.get_precision('Product Unit of Measure'),
)


class StockMove(models.Model):
_inherit = ['stock.move', 'stock.secondary.unit.mixin']
_name = 'stock.move'

def _merge_moves_fields(self):
res = super(StockMove, self)._merge_moves_fields()
res['secondary_uom_qty'] = self[-1:].secondary_uom_qty
return res


class StockMoveLine(models.Model):
_inherit = ['stock.move.line', 'stock.secondary.unit.mixin']
_name = 'stock.move.line'

@api.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'])
factor = move.secondary_uom_id.factor * uom.factor
move_line_qty = vals.get(
'product_uom_qty', vals.get('qty_done', 0.0))
qty = float_round(
move_line_qty / (factor or 1.0),
precision_rounding=move.secondary_uom_id.uom_id.factor
)
vals.update({
'secondary_uom_qty': qty,
'secondary_uom_id': move.secondary_uom_id.id,
})
return super().create(vals)
2 changes: 2 additions & 0 deletions stock_secondary_unit/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Carlos Dauden <[email protected]>
* Sergio Teruel <[email protected]>
2 changes: 2 additions & 0 deletions stock_secondary_unit/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module extends the functionality of stock module to allow define
other units with their conversion factor.
8 changes: 8 additions & 0 deletions stock_secondary_unit/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
To use this module you need to:

#. Go to a *Product > General Information tab*.
#. Create any record in "Secondary unit of measure".
#. Set the conversion factor.
#. Go to *Inventory tab* and set a second unit of measure.
#. Push button 'Quantity on hand' and set quantities in stock for this product.
#. Go to product list and you can see the secondary unit value.
27 changes: 27 additions & 0 deletions stock_secondary_unit/report/report_deliveryslip.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 Tecnativa - Sergio Teruel
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>

<template id="report_delivery_document" inherit_id="stock.report_delivery_document" priority="8">
<xpath expr='//table[@t-if="o.state!=&apos;done&apos;"]/thead/tr/th' position="after">
<th><strong>Secondary Qty</strong></th>
</xpath>
<xpath expr="//span[@t-field='move.product_id']/.." position="after">
<td>
<span t-field="move.secondary_uom_qty"/>
<span t-field="move.secondary_uom_id.name"/>
</td>
</xpath>
<xpath expr='//table[@t-if="o.move_line_ids and o.state==&apos;done&apos;"]/thead/tr/th' position="after">
<th><strong>Secondary Qty</strong></th>
</xpath>
<xpath expr="//span[@t-field='move_line.product_id']/.." position="after">
<td>
<span t-field="move_line.secondary_uom_qty"/>
<span t-field="move_line.secondary_uom_id"/>
</td>
</xpath>
</template>

</odoo>
Binary file added stock_secondary_unit/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions stock_secondary_unit/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import test_stock_secondary_unit
Loading

0 comments on commit d84776c

Please sign in to comment.