Files
tryton/inventory.py
T

60 lines
2.2 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
2012-01-02 18:08:41 +01:00
from trytond.wizard import Wizard, StateView, StateAction, Button
2010-08-10 11:58:50 -04:00
from trytond.transaction import Transaction
2011-07-03 13:19:15 +02:00
from trytond.pool import Pool
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)
2009-01-15 18:09:28 +01:00
lost_found = fields.Many2One(
'stock.location', 'Lost and Found', required=True,
domain=[('type', '=', 'lost_found')])
2012-03-14 09:34:13 +01:00
company = fields.Many2One('company.company', 'Company', required=True,
select=True)
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')])
2012-09-24 22:18:19 +02:00
@classmethod
def default_lost_found(cls):
Location = Pool().get('stock.location')
locations = Location.search(cls.lost_found.domain)
if len(locations) == 1:
return locations[0].id
2009-01-15 18:09:28 +01:00
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
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')
2012-09-24 22:18:19 +02:00
def do_create_(self, action):
Inventory = Pool().get('stock.inventory')
2009-01-15 18:09:28 +01:00
2013-01-06 22:18:14 +01:00
to_create = []
2012-09-24 22:18:19 +02:00
for location in self.start.locations:
2013-01-06 22:18:14 +01:00
to_create.append({
2012-09-24 22:18:19 +02:00
'location': location.id,
'date': self.start.date,
'lost_found': self.start.lost_found.id,
'company': self.start.company.id,
2013-01-06 22:18:14 +01:00
})
if to_create:
inventories = Inventory.create(to_create)
2009-01-15 18:09:28 +01:00
2012-09-24 22:18:19 +02:00
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