Files
tryton/modules/stock_inventory_location/inventory.py
T

82 lines
2.7 KiB
Python
Raw Normal View History

2014-12-02 12:56:07 +01:00
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
2009-02-28 17:05:08 +01:00
from trytond.model import ModelView, fields
2011-07-03 13:19:15 +02:00
from trytond.pool import Pool
2021-12-11 17:58:44 +01:00
from trytond.transaction import Transaction
from trytond.wizard import Button, StateAction, StateView, Wizard
2009-01-15 18:09:28 +01:00
2012-01-02 18:08:41 +01:00
class CreateInventoriesStart(ModelView):
'Create Inventories'
2012-09-24 22:18:19 +02:00
__name__ = 'stock.inventory.create.start'
2009-03-18 18:05:38 +01:00
date = fields.Date('Date', required=True)
company = fields.Many2One('company.company', "Company", required=True)
empty_quantity = fields.Selection(
'get_empty_quantities', "Empty Quantity",
help="How lines without a quantity are handled.")
complete_lines = fields.Boolean(
"Complete",
help="Add an inventory line for each missing product.")
2009-03-05 14:54:45 +01:00
locations = fields.Many2Many('stock.location', None, None,
2009-01-15 18:09:28 +01:00
'Locations', required=True, domain=[('type', '=', 'storage')])
@classmethod
def default_date(cls):
return Pool().get('ir.date').today()
2012-09-24 22:18:19 +02:00
@staticmethod
def default_company():
2012-03-27 10:44:07 +02:00
return Transaction().context.get('company')
2009-01-15 18:09:28 +01:00
@classmethod
def get_empty_quantities(cls):
pool = Pool()
Inventory = pool.get('stock.inventory')
return Inventory.fields_get(
['empty_quantity'])['empty_quantity']['selection']
@classmethod
def default_empty_quantity(cls):
pool = Pool()
Inventory = pool.get('stock.inventory')
try:
return Inventory.default_empty_quantity()
except AttributeError:
return
@classmethod
def default_complete_lines(cls):
return True
2009-01-15 18:09:28 +01:00
class CreateInventories(Wizard):
'Create Inventories'
2012-09-24 22:18:19 +02:00
__name__ = 'stock.inventory.create'
2012-01-02 18:08:41 +01:00
start = StateView('stock.inventory.create.start',
'stock_inventory_location.inventory_create_start_view_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Create', 'create_', 'tryton-ok', default=True),
])
create_ = StateAction('stock.act_inventory_form')
def get_inventory(self, location, Inventory):
return Inventory(
location=location,
date=self.start.date,
company=self.start.company,
empty_quantity=self.start.empty_quantity)
2012-09-24 22:18:19 +02:00
def do_create_(self, action):
pool = Pool()
Inventory = pool.get('stock.inventory')
2009-01-15 18:09:28 +01:00
inventories = [
self.get_inventory(location, Inventory)
for location in self.start.locations]
Inventory.save(inventories)
2009-01-15 18:09:28 +01:00
if self.start.complete_lines:
Inventory.complete_lines(inventories)
2009-01-15 18:09:28 +01:00
2012-09-24 22:18:19 +02:00
data = {'res_id': [i.id for i in inventories]}
2012-01-02 18:08:41 +01:00
return action, data