Skip to content
Snippets Groups Projects
Commit 6e387294 authored by Nicolas Martinelli's avatar Nicolas Martinelli
Browse files

[ADD] product_uos: adaptation due to the new Sale module

New module to centralize UoS management.

Reason: complete rewrite of the Sale module.

Responsible: fp, dbo, nim
parent d152106b
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import models
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name': 'Sale - Secondary UoM',
'version': '1.0',
'category': 'Sales Management',
'sequence': 14,
'summary': 'Unit of Sale',
'description': """
Manage secondary units of sale
==============================
Sell products in one unit of measure that is different from the one
you manage the inventory.
""",
'author': 'Odoo',
'website': 'https://www.odoo.com',
'depends': ['sale'],
'data': [
'views/product_uos_view.xml',
],
'installable': True,
'auto_install': False,
}
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import product_uos
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from openerp import api, fields, models
import openerp.addons.decimal_precision as dp
class ProductTemplate(models.Model):
_inherit = "product.template"
uos_id = fields.Many2one('product.uom', 'Unit of Sale',
help='Specify a unit of measure here if invoicing is made in another'
' unit of measure than inventory. Keep empty to use the default unit of measure.')
uos_coeff = fields.Float('Unit of Measure -> UOS Coeff', digits_compute=dp.get_precision('Product Unit of Measure'),
help='Coefficient to convert default Unit of Measure to Unit of Sale'
' uos = uom * coeff')
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
@api.one
def _set_uos(self):
if self.product_id.uos_coeff:
self.product_uom_qty = self.product_uos_qty / self.product_id.uos_coeff
self.product_uom = self.product_id.uom_id
@api.one
def _compute_uos(self):
self.product_uos_qty = self.product_uom_qty * self.product_id.uos_coeff
product_uos_qty = fields.Float(string='Quantity', digits_compute=dp.get_precision('Product Unit of Measure'),
compute='_compute_uos', inverse='_set_uos', readonly=False)
product_uos = fields.Many2one('product.uom', string='Unit of Measure', required=True,
related='product_id.uos_id', readonly=True)
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Inherit Form view -->
<record id="product_template_form_view_inherit_product_uos" model="ir.ui.view">
<field name="name">product.template.common.form.inherit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="after">
<group groups="product.group_uos" string="Unit of Measure">
<field name="uos_id" options="{'no_open':True,'no_create':True}"/>
<field name="uos_coeff" groups="base.group_no_one"/>
</group>
</xpath>
</field>
</record>
</data>
</openerp>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment