[REF] barcodes, stock, point_of_sale: one nomenclature per company
This commit adds a many2one between barcode.nomenclature and res.company and removes Many2one pointing toward a nomenclature record. This aims to improve the usability and allows using nomenclature in inventory adjustment where a `nomenclature_id` field was set.
This commit is contained in:
committed by
Simon Lejeune
parent
acace4d8c3
commit
95a9572da3
@@ -1,3 +1,18 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import models
|
||||
|
||||
from odoo import api, SUPERUSER_ID
|
||||
|
||||
|
||||
def _assign_default_nomeclature_id(cr, registry):
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
company_ids_without_default_nomenclature_id = env['res.company'].search([
|
||||
('nomenclature_id', '=', False)
|
||||
])
|
||||
default_nomenclature_id = env.ref('barcodes.default_barcode_nomenclature', raise_if_not_found=False)
|
||||
if default_nomenclature_id:
|
||||
company_ids_without_default_nomenclature_id.write({
|
||||
'nomenclature_id': default_nomenclature_id.id,
|
||||
})
|
||||
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
'views/barcodes_view.xml',
|
||||
'security/ir.model.access.csv',
|
||||
'views/barcodes_templates.xml',
|
||||
'views/res_company.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'auto_install': False,
|
||||
'post_init_hook': '_assign_default_nomeclature_id',
|
||||
}
|
||||
|
||||
@@ -2,3 +2,4 @@
|
||||
from . import barcodes
|
||||
from . import barcode_events_mixin
|
||||
from . import ir_http
|
||||
from . import res_company
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import models, fields
|
||||
|
||||
|
||||
class ResCompany(models.Model):
|
||||
_inherit = 'res.company'
|
||||
|
||||
def _get_default_nomenclature(self):
|
||||
return self.env.ref('barcodes.default_barcode_nomenclature', raise_if_not_found=False)
|
||||
|
||||
nomenclature_id = fields.Many2one(
|
||||
'barcode.nomenclature',
|
||||
string="Nomenclature",
|
||||
default=_get_default_nomenclature,
|
||||
)
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
<record model="ir.ui.view" id="view_company_form_inherit">
|
||||
<field name="name">barcode.company.form</field>
|
||||
<field name="model">res.company</field>
|
||||
<field name="inherit_id" ref="base.view_company_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='currency_id']" position="after">
|
||||
<field name="nomenclature_id"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -291,7 +291,7 @@ class PosConfig(models.Model):
|
||||
@api.onchange('barcode_scanner')
|
||||
def _onchange_barcode_scanner(self):
|
||||
if self.barcode_scanner:
|
||||
self.barcode_nomenclature_id = self.env['barcode.nomenclature'].search([], limit=1)
|
||||
self.barcode_nomenclature_id = self.env.user.company_id.nomenclature_id
|
||||
else:
|
||||
self.barcode_nomenclature_id = False
|
||||
|
||||
|
||||
@@ -59,9 +59,6 @@ class PickingType(models.Model):
|
||||
rate_picking_late = fields.Integer(compute='_compute_picking_count')
|
||||
rate_picking_backorders = fields.Integer(compute='_compute_picking_count')
|
||||
|
||||
barcode_nomenclature_id = fields.Many2one(
|
||||
'barcode.nomenclature', 'Barcode Nomenclature')
|
||||
|
||||
@api.one
|
||||
def _compute_last_done_picking(self):
|
||||
# TDE TODO: true multi
|
||||
|
||||
@@ -45,7 +45,6 @@
|
||||
<group>
|
||||
<field name="code"/>
|
||||
<field attrs='{"invisible": [("code", "not in", ["incoming", "outgoing", "internal"])]}' name="return_picking_type_id"/>
|
||||
<field attrs='{"invisible": [("code", "not in", ["incoming", "outgoing", "internal"])]}' name="barcode_nomenclature_id" groups="base.group_no_one"/>
|
||||
<field name="show_operations"/>
|
||||
<field name="show_reserved" attrs="{'invisible': [('show_operations', '!=', False)]}"/>
|
||||
</group>
|
||||
|
||||
Reference in New Issue
Block a user