parent
3e130acf89
commit
8522fcad79
|
@ -5,9 +5,6 @@ from . import stock
|
|||
|
||||
|
||||
def register():
|
||||
Pool.register(
|
||||
stock.Lot,
|
||||
module='stock_lot_jreport', type_='model')
|
||||
Pool.register(
|
||||
stock.LotReport,
|
||||
module='stock_lot_jreport', type_='report')
|
||||
|
|
12
locale/ca.po
12
locale/ca.po
|
@ -2,14 +2,6 @@
|
|||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:stock.lot,lag_quantity:"
|
||||
msgid "Lag Quantity"
|
||||
msgstr "Quantitat de retard"
|
||||
|
||||
msgctxt "field:stock.lot,warehouse:"
|
||||
msgid "Warehouse"
|
||||
msgstr "Magatzem"
|
||||
|
||||
msgctxt "report:stock.lot.jreport:"
|
||||
msgid "Date"
|
||||
msgstr "Data"
|
||||
|
@ -41,7 +33,3 @@ msgstr "Quantitat"
|
|||
msgctxt "report:stock.lot.jreport:"
|
||||
msgid "Warehouse"
|
||||
msgstr "Magatzem"
|
||||
|
||||
msgctxt "model:ir.action,name:stock_lot_report_action"
|
||||
msgid "Stock Lot"
|
||||
msgstr "Lot"
|
||||
|
|
12
locale/es.po
12
locale/es.po
|
@ -2,14 +2,6 @@
|
|||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:stock.lot,lag_quantity:"
|
||||
msgid "Lag Quantity"
|
||||
msgstr "Cantidad de retraso"
|
||||
|
||||
msgctxt "field:stock.lot,warehouse:"
|
||||
msgid "Warehouse"
|
||||
msgstr "Almacén"
|
||||
|
||||
msgctxt "report:stock.lot.jreport:"
|
||||
msgid "Date"
|
||||
msgstr "Fecha"
|
||||
|
@ -41,7 +33,3 @@ msgstr "Importe"
|
|||
msgctxt "report:stock.lot.jreport:"
|
||||
msgid "Warehouse"
|
||||
msgstr "Almacén"
|
||||
|
||||
msgctxt "model:ir.action,name:stock_lot_report_action"
|
||||
msgid "Stock Lot"
|
||||
msgstr "Lote stock"
|
||||
|
|
60
stock.py
60
stock.py
|
@ -7,65 +7,7 @@ from trytond.pool import Pool, PoolMeta
|
|||
from trytond.transaction import Transaction
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
__all__ = ['Lot', 'LotReport']
|
||||
|
||||
|
||||
class Lot(metaclass=PoolMeta):
|
||||
__name__ = 'stock.lot'
|
||||
|
||||
lag_quantity = fields.Function(fields.Float('Lag Quantity'),
|
||||
'get_lag_quantity', searcher='search_lag_quantity')
|
||||
warehouse = fields.Function(fields.Many2One('stock.location',
|
||||
'Warehouse'), 'get_warehouse')
|
||||
|
||||
@classmethod
|
||||
def get_lag_quantity(cls, lots, name):
|
||||
pool = Pool()
|
||||
Date = pool.get('ir.date')
|
||||
Location = pool.get('stock.location')
|
||||
|
||||
configuration = pool.get('stock.configuration')(1)
|
||||
|
||||
location_ids = (configuration.warehouse and
|
||||
[configuration.warehouse.id] or [])
|
||||
|
||||
if not location_ids:
|
||||
warehouses = Location.search([('type', '=', 'warehouse')])
|
||||
location_ids = [w.storage_location.id for w in warehouses]
|
||||
|
||||
lag_days = configuration.lag_days or 0
|
||||
stock_date_end = Date.today() + relativedelta(days=int(lag_days))
|
||||
with Transaction().set_context({'stock_date_end': stock_date_end}):
|
||||
quantities = cls._get_quantity(lots, name, location_ids,
|
||||
grouping=('product', 'lot'))
|
||||
return quantities
|
||||
|
||||
@classmethod
|
||||
def search_lag_quantity(cls, name, domain=None):
|
||||
pool = Pool()
|
||||
Date = pool.get('ir.date')
|
||||
configuration = pool.get('stock.configuration')(1)
|
||||
Location = pool.get('stock.location')
|
||||
|
||||
location_ids = (configuration.warehouse and
|
||||
[configuration.warehouse.id] or [])
|
||||
|
||||
if not location_ids:
|
||||
warehouses = Location.search([('type', '=', 'warehouse')])
|
||||
location_ids = [w.storage_location.id for w in warehouses]
|
||||
|
||||
lag_days = configuration.lag_days or 0
|
||||
stock_date_end = Date.today() + relativedelta(days=int(lag_days))
|
||||
with Transaction().set_context({'stock_date_end': stock_date_end}):
|
||||
return cls._search_quantity(name, location_ids, domain,
|
||||
grouping=('product', 'lot'))
|
||||
|
||||
@classmethod
|
||||
def get_warehouse(cls, lots, name):
|
||||
configuration = Pool().get('stock.configuration')(1)
|
||||
warehouse_id = (configuration.warehouse and
|
||||
configuration.warehouse.id or None)
|
||||
return {l.id: warehouse_id for l in lots}
|
||||
__all__ = ['LotReport']
|
||||
|
||||
|
||||
class LotReport(JasperReport):
|
||||
|
|
12
stock.xml
12
stock.xml
|
@ -4,18 +4,6 @@ The COPYRIGHT file at the top level of this repository contains the full
|
|||
copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data>
|
||||
<!-- stock.lot -->
|
||||
<record model="ir.ui.view" id="lot_view_form">
|
||||
<field name="model">stock.lot</field>
|
||||
<field name="inherit" ref="stock_lot.lot_view_form"/>
|
||||
<field name="name">lot_form</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="lot_view_tree">
|
||||
<field name="model">stock.lot</field>
|
||||
<field name="inherit" ref="stock_lot.lot_view_tree"/>
|
||||
<field name="name">lot_tree</field>
|
||||
</record>
|
||||
|
||||
<!-- stock.lot.jreport -->
|
||||
<record model="ir.action.report" id="stock_lot_report_action">
|
||||
<field name="name">Stock Lot</field>
|
||||
|
|
|
@ -17,110 +17,6 @@ class TestCase(ModuleTestCase):
|
|||
'Test module'
|
||||
module = 'stock_lot_jreport'
|
||||
|
||||
@with_transaction()
|
||||
def test0010get_lag_quantity(self):
|
||||
'Test get_lag_quantity'
|
||||
pool = Pool()
|
||||
StockConfiguration = pool.get('stock.configuration')
|
||||
Uom = pool.get('product.uom')
|
||||
Template = pool.get('product.template')
|
||||
Product = pool.get('product.product')
|
||||
Location = pool.get('stock.location')
|
||||
Move = pool.get('stock.move')
|
||||
Lot = pool.get('stock.lot')
|
||||
|
||||
# Create Company
|
||||
company = create_company()
|
||||
with set_company(company):
|
||||
|
||||
supplier, = Location.search([('code', '=', 'SUP')])
|
||||
customer, = Location.search([('code', '=', 'CUS')])
|
||||
storage, = Location.search([('code', '=', 'STO')])
|
||||
warehouse, = Location.search([('code', '=', 'WH')])
|
||||
|
||||
StockConfiguration.create([{
|
||||
'warehouse': warehouse.id,
|
||||
'lag_days': 1,
|
||||
}])
|
||||
|
||||
unit, = Uom.search([('name', '=', 'Unit')])
|
||||
template, = Template.create([{
|
||||
'name': 'Test period',
|
||||
'type': 'goods',
|
||||
'cost_price_method': 'fixed',
|
||||
'default_uom': unit.id,
|
||||
'list_price': Decimal(0),
|
||||
}])
|
||||
product, = Product.create([{
|
||||
'template': template.id,
|
||||
}])
|
||||
|
||||
lot1, lot2 = Lot.create([{
|
||||
'number': '1',
|
||||
'product': product.id,
|
||||
}, {
|
||||
'number': '2',
|
||||
'product': product.id,
|
||||
}])
|
||||
|
||||
today = datetime.date.today()
|
||||
moves = Move.create([{
|
||||
'product': product.id,
|
||||
'lot': lot1.id,
|
||||
'uom': unit.id,
|
||||
'quantity': 5,
|
||||
'from_location': supplier.id,
|
||||
'to_location': storage.id,
|
||||
'unit_price': Decimal('1'),
|
||||
}, {
|
||||
'product': product.id,
|
||||
'lot': lot2.id,
|
||||
'uom': unit.id,
|
||||
'quantity': 10,
|
||||
'from_location': supplier.id,
|
||||
'to_location': storage.id,
|
||||
'unit_price': Decimal('1'),
|
||||
}, {
|
||||
'product': product.id,
|
||||
'lot': lot2.id,
|
||||
'uom': unit.id,
|
||||
'quantity': 2,
|
||||
'from_location': storage.id,
|
||||
'to_location': customer.id,
|
||||
'unit_price': Decimal('1'),
|
||||
}, {
|
||||
'product': product.id,
|
||||
'lot': lot1.id,
|
||||
'uom': unit.id,
|
||||
'quantity': 5,
|
||||
'from_location': supplier.id,
|
||||
'to_location': storage.id,
|
||||
'planned_date': today + relativedelta(days=2),
|
||||
'effective_date': today + relativedelta(days=2),
|
||||
'unit_price': Decimal('1'),
|
||||
}, {
|
||||
'product': product.id,
|
||||
'lot': lot2.id,
|
||||
'uom': unit.id,
|
||||
'quantity': 10,
|
||||
'from_location': supplier.id,
|
||||
'to_location': storage.id,
|
||||
'planned_date': today - relativedelta(days=1),
|
||||
'effective_date': today - relativedelta(days=1),
|
||||
'unit_price': Decimal('1'),
|
||||
}])
|
||||
Move.do(moves)
|
||||
|
||||
quantities = {
|
||||
'1': 5,
|
||||
'2': 18,
|
||||
}
|
||||
|
||||
lots = Lot.search([])
|
||||
for lot in lots:
|
||||
self.assertEqual(lot.lag_quantity, quantities[lot.number])
|
||||
|
||||
|
||||
def suite():
|
||||
suite = trytond.tests.test_tryton.suite()
|
||||
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestCase))
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part of stock_lot_jreport module for Tryton.
|
||||
The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/form/field[@name='product']" position="after">
|
||||
<label name="lag_quantity"/>
|
||||
<field name="lag_quantity"/>
|
||||
<label name="warehouse"/>
|
||||
<field name="warehouse"/>
|
||||
</xpath>
|
||||
</data>
|
|
@ -1,10 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part of stock_lot_jreport module for Tryton.
|
||||
The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/tree/field[@name='product']" position="after">
|
||||
<field name="lag_quantity"/>
|
||||
<field name="warehouse"/>
|
||||
</xpath>
|
||||
</data>
|
Loading…
Reference in New Issue