trytond-product_bulk/stock.py

35 lines
1.0 KiB
Python
Raw Permalink Normal View History

2020-01-13 16:09:22 +01:00
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from trytond.model import fields
from trytond.pool import PoolMeta, Pool
2022-05-04 15:21:30 +02:00
from trytond.pyson import Eval
from trytond.modules.stock.move import STATES
2020-01-13 16:09:22 +01:00
__all__ = ['StockMove']
class StockMove(metaclass=PoolMeta):
__name__ = 'stock.move'
bulk_product = fields.Many2One('product.product', 'Bulk Product',
2022-05-04 15:21:30 +02:00
states=STATES, context={
'company': Eval('company', -1),
2022-05-04 15:21:30 +02:00
},
depends=['company'])
2020-01-13 16:09:22 +01:00
# TODO: check if is necessary
@classmethod
def create(cls, vlist):
pool = Pool()
Product = pool.get('product.product')
vlist = [x.copy() for x in vlist]
for vals in vlist:
product = Product(vals['product'])
if product.bulk_type:
vals['bulk_product'] = product
else:
vals['bulk_product'] = product.bulk_product
moves = super().create(vlist)
return moves