37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import models, api
|
|
|
|
|
|
class QuantPackage(models.Model):
|
|
_inherit = 'stock.quant.package'
|
|
_barcode_field = 'name'
|
|
|
|
@api.model
|
|
def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):
|
|
args = self.env.company.nomenclature_id._preprocess_gs1_search_args(args, ['package'], 'name')
|
|
return super()._search(args, offset=offset, limit=limit, order=order, count=count, access_rights_uid=access_rights_uid)
|
|
|
|
@api.model
|
|
def action_create_from_barcode(self, vals_list):
|
|
""" Creates a new package then returns its data to be added in the client side cache.
|
|
"""
|
|
res = self.create(vals_list)
|
|
return {
|
|
'stock.quant.package': res.read(self._get_fields_stock_barcode(), False)
|
|
}
|
|
|
|
@api.model
|
|
def _get_fields_stock_barcode(self):
|
|
return ['name', 'location_id', 'package_type_id', 'quant_ids']
|
|
|
|
@api.model
|
|
def _get_usable_packages(self):
|
|
usable_packages_domain = [
|
|
'|',
|
|
('package_use', '=', 'reusable'),
|
|
('location_id', '=', False),
|
|
]
|
|
return self.env['stock.quant.package'].search(usable_packages_domain)
|