Skip to content
This repository has been archived by the owner on May 13, 2019. It is now read-only.

Commit

Permalink
[ADD] #1 Add United Nations UOM object to relate on product UOM
Browse files Browse the repository at this point in the history
  • Loading branch information
kryskool committed Nov 1, 2014
1 parent e7ee2eb commit ee76ca7
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 3 deletions.
26 changes: 24 additions & 2 deletions classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,37 @@ def _check_code(self, cr, uid, ids, context=None):
if len(rec.code) != 8:
return False
try:
code = int(rec.code)
except:
int(rec.code)
except ValueError:
return False
return True

_constraints = [
(_check_code, 'Error: Code must have 8 digits only', ['code']),
]

_sql_constraints = [
('code_unique', 'UNIQUE (code)', 'The UNSPSC code must be unique !'),
]


class UnitedNationsUOM(orm.Model):
_name = 'product.uom.un'
_description = 'United Nations UOM'

_columns = {
'name': fields.char('Name', size=256, translate=True),
'code': fields.char('Code', size=64, help='Common code'),
'description': fields.text('Description', translate=True),
'symbol': fields.char('Symbol', size=64, help='Symbole of the uom'),
'factor': fields.char(
'Conversion Factor', size=128,
help='Conversion factor'),
}

_sql_constraints = [
('code_unique', 'UNIQUE (code)', 'The UNSPSC code must be unique !'),
]


# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
85 changes: 85 additions & 0 deletions classification_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#
##############################################################################

<!-- ************************************************************** -->
<!-- ** UNSPSC code *********************************************** -->
<!-- ************************************************************** -->

<record id="view_product_category_unspsc_tree" model="ir.ui.view">
<field name="name">product.category.unspsc.tree</field>
<field name="model">product.category.unspsc</field>
Expand Down Expand Up @@ -94,5 +98,86 @@
sequence="20"
action="act_open_product_category_unspsc_view"/>

<!-- ************************************************************** -->
<!-- ** UNUOM see UN/ECE Recommandation 20 ************************ -->
<!-- ************************************************************** -->
<record id="view_product_uom_un_tree" model="ir.ui.view">
<field name="name">product.uom.un.tree</field>
<field name="model">product.uom.un</field>
<field name="type">tree</field>
<field name="priority" eval="8"/>
<field name="arch" type="xml">
<tree string="UNUOM">
<field name="code"/>
<field name="name"/>
<field name="symbol"/>
<field name="factor"/>
</tree>
</field>
</record>

<record id="view_product_uom_un_form" model="ir.ui.view">
<field name="name">product.uom.un.form</field>
<field name="model">product.uom.un</field>
<field name="type">form</field>
<field name="priority" eval="8"/>
<field name="arch" type="xml">
<form string="UNUOM">
<field name="code"/>
<field name="name"/>
<field name="symbol"/>
<field name="factor"/>
<separator string="Description" colspan="4"/>
<field name="description" colspan="4" nolabel="1" />
</form>
</field>
</record>

<record id="view_product_uom_un_search" model="ir.ui.view">
<field name="name">product.uom.un.search</field>
<field name="model">product.uom.un</field>
<field name="type">search</field>
<field name="priority" eval="8"/>
<field name="arch" type="xml">
<search string="UNUOM">
<field name="code"/>
<field name="name"/>
<field name="symbol"/>
<field name="factor"/>
<field name="description"/>
</search>
</field>
</record>

<record model="ir.actions.act_window" id="act_open_product_uom_un_view">
<field name="name">UNUOM</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">product.uom.un</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="search_view_id" ref="view_product_uom_un_search"/>
<field name="domain">[]</field>
<field name="context">{}</field>
</record>

<record model="ir.actions.act_window.view" id="act_open_product_uom_un_view_form">
<field name="act_window_id" ref="act_open_product_uom_un_view"/>
<field name="sequence" eval="20"/>
<field name="view_mode">form</field>
<field name="view_id" ref="view_product_uom_un_form"/>
</record>

<record model="ir.actions.act_window.view" id="act_open_product_uom_un_view_tree">
<field name="act_window_id" ref="act_open_product_uom_un_view"/>
<field name="sequence" eval="10"/>
<field name="view_mode">tree</field>
<field name="view_id" ref="view_product_uom_un_tree"/>
</record>

<menuitem id="menu_product_uom_un"
parent="product.prod_config_main"
sequence="20"
action="act_open_product_uom_un_view"/>

</data>
</openerp>
11 changes: 11 additions & 0 deletions data/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ This folder contains file to import manually

Use PostgreSQL COPY command to import the files

UNSPSC
------

Usage::

copy product_category_unspsc (code, name) from 'unspsc-computers.csv' WITH DELIMITER ';';


UNUOM
-----

Download Recommendation No. 20 (Codes for Units of Measure used in International Trade) to find how unit of measure is organized.


30 changes: 30 additions & 0 deletions data/unuom-level-1-normative-units.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
KEL;kelvin;Refer ISO 80000-5 (Quantities and units — Part 5: Thermodynamics);K;K
KGM;kilogram;A unit of mass equal to one thousand grams.;kg;kg
KGS;kilogram per second;;kg/s;kg/s
KL;kilogram per metre;;kg/m;kg/m
KMQ;kilogram per cubic metre;A unit of weight expressed in kilograms of a substance that fills a volume of one cubic metre.;kg/m³;kg/m³
KNT;knot;;kn;0,514 444 m/s
LTR;litre;;l;10⁻³ m³
LUM;lumen;;lm;cd x sr
LUX;lux;;lx;cd x sr / m²
MIN;minute [unit of time];;min;60 s
MQS;cubic metre per second;;m³/s;m³/s
MSK;metre per second squared;;m/s²;m/s²
MTK;square metre;;m²;m²
MTQ;cubic metre;Synonym: metre cubed;m³;m³
MTR;metre;;m;m
MTS;metre per second;;m/s;m/s
NEW;newton;;N;(kg x m)/s²
NMI;nautical mile;;n mile;1 852 m
NU;newton metre;;N·m;N x m
OHM;ohm;;Ω;Ω
PAL;pascal;;Pa;Pa
RPM;revolutions per minute;Refer ISO/TC12 SI Guide;r/min;1,67 x 10⁻²/s
RPS;revolutions per second;Refer ISO/TC12 SI Guide;r/s;1/s
S4;square metre per second;Synonym: metre squared per second (square metres/second US);m²/s;m²/s
SEC;second [unit of time];;s;s
SIE;siemens;;S;A/V
VLT;volt;;V;V
WEB;weber;;Wb;Wb
WHR;watt hour;;W·h;3,6 x 10³ J
WTT;watt;;W;W
10 changes: 10 additions & 0 deletions product.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ class ProductCategory(orm.Model):
}


class ProductUOM(orm.Model):
_inherit = 'product.uom'

_columns = {
'unuom_id': fields.many2one(
'product.uom.un', 'UNUOM',
help='Link current UOM to the UNUOM reference'),
}


class Product(orm.Model):
_inherit = 'product.product'

Expand Down
22 changes: 21 additions & 1 deletion product_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@
</field>
</record>


<!-- ************************************************************** -->
<!-- ** Add UNSPSC related field on product category ************** -->
<!-- ************************************************************** -->

<record id="view_product_category_catalog_form" model="ir.ui.view">
<field name="name">product.category.form</field>
<field name="model">product.category</field>
<field name="inherit_id" ref="product.product_category_form_view"/>
<field name="priority" eval="8"/>
<field name="priority" eval="20"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='type']" position="after">
<field name="unspsc_id"/>
Expand All @@ -51,5 +56,20 @@
</field>
</record>

<!-- ************************************************************** -->
<!-- ************************************************************** -->
<!-- ************************************************************** -->
<record id="view_product_uom_un_catalog_form" model="ir.ui.view">
<field name="name">product.uom.form</field>
<field name="model">product.uom</field>
<field name="inherit_id" ref="product.product_uom_form_view"/>
<field name="priority" eval="20"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='rounding']" position="after">
<field name="unuom_id"/>
</xpath>
</field>
</record>

</data>
</openerp>
2 changes: 2 additions & 0 deletions security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ access_product_catalog,access_product_catalog,model_product_catalog,group_produc
access_product_catalog_user,access_product_catalog_user,model_product_catalog,group_product_catalog_manager,1,1,1,1
access_product_category_unspsc,access_product_category_unspsc,model_product_category_unspsc,,1,0,0,0
access_product_category_unspsc_manager,access_product_category_unspsc_manager,model_product_category_unspsc,group_product_catalog_manager,1,1,1,1
access_product_uom_un,access_product_uom_un,model_product_uom_un,,1,0,0,0
access_product_uom_un,access_product_uom_un,model_product_uom_un,group_product_catalog_manager,1,1,1,1

0 comments on commit ee76ca7

Please sign in to comment.