report shipment
This commit is contained in:
parent
cabf8308cd
commit
18b94a1412
|
@ -16,10 +16,12 @@ def register():
|
||||||
shipment.InternalShipment,
|
shipment.InternalShipment,
|
||||||
stock.WarehouseStockStart,
|
stock.WarehouseStockStart,
|
||||||
stock.Inventory,
|
stock.Inventory,
|
||||||
stock.ShipmentInternal,
|
# stock.ShipmentInternal,
|
||||||
|
shipment.ShipmentDetailedStart,
|
||||||
stock.PrintProductsStart,
|
stock.PrintProductsStart,
|
||||||
module='stock_co', type_='model')
|
module='stock_co', type_='model')
|
||||||
Pool.register(
|
Pool.register(
|
||||||
|
shipment.ShipmentDetailed,
|
||||||
stock.PrintMoveByProduct,
|
stock.PrintMoveByProduct,
|
||||||
shipment.CreateInternalShipment,
|
shipment.CreateInternalShipment,
|
||||||
stock.WarehouseStock,
|
stock.WarehouseStock,
|
||||||
|
@ -29,6 +31,7 @@ def register():
|
||||||
module='stock_co', type_='wizard')
|
module='stock_co', type_='wizard')
|
||||||
Pool.register(
|
Pool.register(
|
||||||
stock.MoveByProduct,
|
stock.MoveByProduct,
|
||||||
|
shipment.ShipmentDetailedReport,
|
||||||
stock.WarehouseReport,
|
stock.WarehouseReport,
|
||||||
stock.PrintProductsReport,
|
stock.PrintProductsReport,
|
||||||
module='stock_co', type_='report')
|
module='stock_co', type_='report')
|
||||||
|
|
153
shipment.py
153
shipment.py
|
@ -1,17 +1,35 @@
|
||||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||||
# this repository contains the full copyright notices and license terms.
|
# this repository contains the full copyright notices and license terms.
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
from decimal import Decimal
|
||||||
from sql import Table
|
from sql import Table
|
||||||
from trytond.pool import Pool, PoolMeta
|
from trytond.pool import Pool, PoolMeta
|
||||||
from trytond.wizard import Wizard, StateTransition, StateView, Button
|
from trytond.wizard import Wizard, StateTransition, StateView, Button, StateReport
|
||||||
from trytond.transaction import Transaction
|
from trytond.transaction import Transaction
|
||||||
from trytond.model import ModelView, fields
|
from trytond.model import ModelView, fields
|
||||||
|
from trytond.report import Report
|
||||||
|
from trytond.pyson import Eval
|
||||||
|
|
||||||
|
|
||||||
class InternalShipment(metaclass=PoolMeta):
|
class InternalShipment(metaclass=PoolMeta):
|
||||||
'Internal Shipment'
|
'Internal Shipment'
|
||||||
__name__ = 'stock.shipment.internal'
|
__name__ = 'stock.shipment.internal'
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __setup__(cls):
|
||||||
|
super(InternalShipment, cls).__setup__()
|
||||||
|
cls.reference.states = {
|
||||||
|
'required': Eval('state').in_(['draft']),
|
||||||
|
}
|
||||||
|
# cls.from_location.domain = [
|
||||||
|
# ('party', '=', Eval('company_party', -1)),
|
||||||
|
# ('type', 'in', cls.tax_identifier_types()),
|
||||||
|
# ]
|
||||||
|
# cls.to_location.domain = [
|
||||||
|
# ('party', '=', Eval('company_party', -1)),
|
||||||
|
# ('type', 'in', cls.tax_identifier_types()),
|
||||||
|
# ]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def wait(cls, shipments):
|
def wait(cls, shipments):
|
||||||
super(InternalShipment, cls).wait(shipments)
|
super(InternalShipment, cls).wait(shipments)
|
||||||
|
@ -28,6 +46,64 @@ class InternalShipment(metaclass=PoolMeta):
|
||||||
if employee_id:
|
if employee_id:
|
||||||
cls.write(shipments, {field: employee_id})
|
cls.write(shipments, {field: employee_id})
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def import_data(cls, fields_names, data):
|
||||||
|
pool = Pool()
|
||||||
|
Move = pool.get('stock.move')
|
||||||
|
Location = pool.get('stock.location')
|
||||||
|
Product = pool.get('product.product')
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
head = data[0]
|
||||||
|
from_ = head[1]
|
||||||
|
to_ = head[2]
|
||||||
|
shp_date = head[0]
|
||||||
|
year, month, day = shp_date.split('-')
|
||||||
|
date_ = date(int(year), int(month), int(day))
|
||||||
|
from_locations = Location.search([
|
||||||
|
('code', '=', from_),
|
||||||
|
('type', 'in', ['view', 'storage', 'lost_found'])
|
||||||
|
])
|
||||||
|
to_locations = Location.search([
|
||||||
|
('code', '=', to_),
|
||||||
|
('type', 'in', ['view', 'storage', 'lost_found'])
|
||||||
|
])
|
||||||
|
if not from_locations or not to_locations:
|
||||||
|
return count
|
||||||
|
else:
|
||||||
|
from_location_id = from_locations[0].id
|
||||||
|
to_location_id = to_locations[0].id
|
||||||
|
|
||||||
|
shipment, = cls.create([{
|
||||||
|
'effective_date': date_,
|
||||||
|
'planned_date': date_,
|
||||||
|
'planned_start_date': date_,
|
||||||
|
'from_location': from_location_id,
|
||||||
|
'to_location': to_location_id,
|
||||||
|
'state': 'draft',
|
||||||
|
}])
|
||||||
|
|
||||||
|
moves_to_create = []
|
||||||
|
for row in data[1:]:
|
||||||
|
count += 1
|
||||||
|
products = Product.search([
|
||||||
|
('code', '=', row[0])
|
||||||
|
])
|
||||||
|
uom_id = products[0].template.default_uom.id
|
||||||
|
moves_to_create.append({
|
||||||
|
'product': products[0].id,
|
||||||
|
'uom': uom_id,
|
||||||
|
'quantity': int(row[1]),
|
||||||
|
'internal_quantity': int(row[1]),
|
||||||
|
'from_location': from_location_id,
|
||||||
|
'to_location': to_location_id,
|
||||||
|
'shipment': str(shipment),
|
||||||
|
'state': 'draft',
|
||||||
|
})
|
||||||
|
|
||||||
|
Move.create(moves_to_create)
|
||||||
|
return count
|
||||||
|
|
||||||
|
|
||||||
class CreateInternalShipmentStart(ModelView):
|
class CreateInternalShipmentStart(ModelView):
|
||||||
'Create Internal Shipment Start'
|
'Create Internal Shipment Start'
|
||||||
|
@ -140,3 +216,78 @@ class ShipmentInternalForceDraft(Wizard):
|
||||||
shipment.state = 'draft'
|
shipment.state = 'draft'
|
||||||
shipment.save()
|
shipment.save()
|
||||||
return 'end'
|
return 'end'
|
||||||
|
|
||||||
|
|
||||||
|
class ShipmentDetailedStart(ModelView):
|
||||||
|
'Shipment Detailed Start'
|
||||||
|
__name__ = 'stock.shipment.shipment_detailed.start'
|
||||||
|
company = fields.Many2One('company.company', 'Company', required=True)
|
||||||
|
start_date = fields.Date('Start Date', required=True)
|
||||||
|
end_date = fields.Date('End Date', required=True)
|
||||||
|
type_shipment = fields.Selection([
|
||||||
|
('in', 'Supplier'),
|
||||||
|
('out', 'Customer'),
|
||||||
|
('internal', 'Internal'),
|
||||||
|
], 'Type Shipment', required=True)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def default_company():
|
||||||
|
return Transaction().context.get('company')
|
||||||
|
|
||||||
|
|
||||||
|
class ShipmentDetailed(Wizard):
|
||||||
|
'Shipment Detailed'
|
||||||
|
__name__ = 'stock.shipment.shipment_detailed'
|
||||||
|
|
||||||
|
start = StateView('stock.shipment.shipment_detailed.start',
|
||||||
|
'stock_co.print_shipment_detailed_start_view_form', [
|
||||||
|
Button('Cancel', 'end', 'tryton-cancel'),
|
||||||
|
Button('Print', 'print_', 'tryton-ok', default=True),
|
||||||
|
])
|
||||||
|
print_ = StateReport('stock.shipment.shipment_detailed.report')
|
||||||
|
|
||||||
|
def do_print_(self, action):
|
||||||
|
data = {
|
||||||
|
'company': self.start.company.id,
|
||||||
|
'start_date': self.start.start_date,
|
||||||
|
'end_date': self.start.end_date,
|
||||||
|
'type_shipment': self.start.type_shipment,
|
||||||
|
}
|
||||||
|
return action, data
|
||||||
|
|
||||||
|
def transition_print_(self):
|
||||||
|
return 'end'
|
||||||
|
|
||||||
|
|
||||||
|
class ShipmentDetailedReport(Report):
|
||||||
|
'Shipment Detailed Report'
|
||||||
|
__name__ = 'stock.shipment.shipment_detailed.report'
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_context(cls, records, header, data):
|
||||||
|
report_context = super().get_context(records, header, data)
|
||||||
|
|
||||||
|
pool = Pool()
|
||||||
|
model = 'stock.shipment.' + data['type_shipment']
|
||||||
|
ModelShipment = pool.get(model)
|
||||||
|
dom_shipment = [
|
||||||
|
('company', '=', data['company']),
|
||||||
|
('effective_date', '>=', data['start_date']),
|
||||||
|
('effective_date', '<=', data['end_date'])
|
||||||
|
]
|
||||||
|
shipments = ModelShipment.search(dom_shipment,
|
||||||
|
order=[('effective_date', 'ASC')]
|
||||||
|
)
|
||||||
|
_records = []
|
||||||
|
for s in shipments:
|
||||||
|
for m in s.moves:
|
||||||
|
value = {
|
||||||
|
'oc': s.to_location.parent.operation_center.name if s.to_location.parent.operation_center else '',
|
||||||
|
'move': m,
|
||||||
|
'shipment': s
|
||||||
|
}
|
||||||
|
_records.append(value)
|
||||||
|
report_context['records'] = _records
|
||||||
|
report_context['Decimal'] = Decimal
|
||||||
|
report_context['data'] = data
|
||||||
|
return report_context
|
||||||
|
|
38
shipment.xml
38
shipment.xml
|
@ -3,6 +3,22 @@
|
||||||
this repository contains the full copyright notices and license terms. -->
|
this repository contains the full copyright notices and license terms. -->
|
||||||
<tryton>
|
<tryton>
|
||||||
<data>
|
<data>
|
||||||
|
|
||||||
|
<record model="ir.ui.view" id="create_internal_shipment_start_view_form">
|
||||||
|
<field name="model">stock_co.create_internal_shipment.start</field>
|
||||||
|
<field name="type">form</field>
|
||||||
|
<field name="name">create_internal_shipment_form</field>
|
||||||
|
</record>
|
||||||
|
<record model="ir.action.wizard" id="act_create_internal_shipment">
|
||||||
|
<field name="name">Create Internal Shipment</field>
|
||||||
|
<field name="wiz_name">stock_co.create_internal_shipment</field>
|
||||||
|
</record>
|
||||||
|
<record model="ir.action.keyword" id="action_move_fix_number_keyword">
|
||||||
|
<field name="keyword">form_action</field>
|
||||||
|
<field name="model">stock.shipment.in,-1</field>
|
||||||
|
<field name="action" ref="act_create_internal_shipment"/>
|
||||||
|
</record>
|
||||||
|
|
||||||
<record model="ir.action.wizard" id="act_shipment_out_force_draft">
|
<record model="ir.action.wizard" id="act_shipment_out_force_draft">
|
||||||
<field name="name">Shipment Out Force Draft</field>
|
<field name="name">Shipment Out Force Draft</field>
|
||||||
<field name="wiz_name">stock.shipment.out.force_draft</field>
|
<field name="wiz_name">stock.shipment.out.force_draft</field>
|
||||||
|
@ -22,6 +38,26 @@ this repository contains the full copyright notices and license terms. -->
|
||||||
<field name="model">stock.shipment.internal,-1</field>
|
<field name="model">stock.shipment.internal,-1</field>
|
||||||
<field name="action" ref="act_shipment_internal_force_draft"/>
|
<field name="action" ref="act_shipment_internal_force_draft"/>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<record model="ir.ui.view" id="print_shipment_detailed_start_view_form">
|
||||||
|
<field name="model">stock.shipment.shipment_detailed.start</field>
|
||||||
|
<field name="type">form</field>
|
||||||
|
<field name="name">print_shipment_detailed_start_form</field>
|
||||||
|
</record>
|
||||||
|
<record model="ir.action.wizard" id="wizard_shipment_detailed">
|
||||||
|
<field name="name">Print Shipment Detailed</field>
|
||||||
|
<field name="wiz_name">stock.shipment.shipment_detailed</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record model="ir.action.report" id="report_shipment_detailed">
|
||||||
|
<field name="name">Shipment Detailed</field>
|
||||||
|
<field name="model"></field>
|
||||||
|
<field name="report_name">stock.shipment.shipment_detailed.report</field>
|
||||||
|
<field name="report">stock_co/purchase_detailed.ods</field>
|
||||||
|
<field name="template_extension">ods</field>
|
||||||
|
<field name="translatable">True</field>
|
||||||
|
</record>
|
||||||
|
<menuitem parent="menu_reports" sequence="100" action="wizard_shipment_detailed"
|
||||||
|
id="menu_print_shipment_detailed" icon="tryton-print"/>
|
||||||
</data>
|
</data>
|
||||||
</tryton>
|
</tryton>
|
||||||
|
|
Binary file not shown.
62
stock.py
62
stock.py
|
@ -539,65 +539,3 @@ class Inventory(metaclass=PoolMeta):
|
||||||
InventoryLine.create(lines_to_create.values())
|
InventoryLine.create(lines_to_create.values())
|
||||||
|
|
||||||
return count
|
return count
|
||||||
|
|
||||||
|
|
||||||
class ShipmentInternal(metaclass=PoolMeta):
|
|
||||||
__name__ = 'stock.shipment.internal'
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def import_data(cls, fields_names, data):
|
|
||||||
pool = Pool()
|
|
||||||
Move = pool.get('stock.move')
|
|
||||||
Location = pool.get('stock.location')
|
|
||||||
Product = pool.get('product.product')
|
|
||||||
|
|
||||||
count = 0
|
|
||||||
head = data[0]
|
|
||||||
from_ = head[1]
|
|
||||||
to_ = head[2]
|
|
||||||
shp_date = head[0]
|
|
||||||
year, month, day = shp_date.split('-')
|
|
||||||
date_ = date(int(year), int(month), int(day))
|
|
||||||
from_locations = Location.search([
|
|
||||||
('code', '=', from_),
|
|
||||||
('type', 'in', ['view', 'storage', 'lost_found'])
|
|
||||||
])
|
|
||||||
to_locations = Location.search([
|
|
||||||
('code', '=', to_),
|
|
||||||
('type', 'in', ['view', 'storage', 'lost_found'])
|
|
||||||
])
|
|
||||||
if not from_locations or not to_locations:
|
|
||||||
return count
|
|
||||||
else:
|
|
||||||
from_location_id = from_locations[0].id
|
|
||||||
to_location_id = to_locations[0].id
|
|
||||||
|
|
||||||
shipment, = cls.create([{
|
|
||||||
'effective_date': date_,
|
|
||||||
'planned_date': date_,
|
|
||||||
'planned_start_date': date_,
|
|
||||||
'from_location': from_location_id,
|
|
||||||
'to_location': to_location_id,
|
|
||||||
'state': 'draft',
|
|
||||||
}])
|
|
||||||
|
|
||||||
moves_to_create = []
|
|
||||||
for row in data[1:]:
|
|
||||||
count += 1
|
|
||||||
products = Product.search([
|
|
||||||
('code', '=', row[0])
|
|
||||||
])
|
|
||||||
uom_id = products[0].template.default_uom.id
|
|
||||||
moves_to_create.append({
|
|
||||||
'product': products[0].id,
|
|
||||||
'uom': uom_id,
|
|
||||||
'quantity': int(row[1]),
|
|
||||||
'internal_quantity': int(row[1]),
|
|
||||||
'from_location': from_location_id,
|
|
||||||
'to_location': to_location_id,
|
|
||||||
'shipment': str(shipment),
|
|
||||||
'state': 'draft',
|
|
||||||
})
|
|
||||||
|
|
||||||
Move.create(moves_to_create)
|
|
||||||
return count
|
|
||||||
|
|
30
stock.xml
30
stock.xml
|
@ -33,8 +33,12 @@ this repository contains the full copyright notices and license terms. -->
|
||||||
<field name="name">Move by Product</field>
|
<field name="name">Move by Product</field>
|
||||||
<field name="wiz_name">stock_co.print_move_by_product</field>
|
<field name="wiz_name">stock_co.print_move_by_product</field>
|
||||||
</record>
|
</record>
|
||||||
<menuitem parent="stock.menu_stock" sequence="100"
|
|
||||||
action="wizard_move_by_product" id="menu_move_by_product"/>
|
<menuitem parent="stock.menu_stock" sequence="200"
|
||||||
|
name="Reports" id="menu_reports" icon="tryton-folder"/>
|
||||||
|
|
||||||
|
<menuitem parent="menu_reports" sequence="100"
|
||||||
|
action="wizard_move_by_product" id="menu_move_by_product"/>
|
||||||
|
|
||||||
<record model="ir.ui.view" id="warehouse_stock_start_view_form">
|
<record model="ir.ui.view" id="warehouse_stock_start_view_form">
|
||||||
<field name="model">stock_co.warehouse_stock.start</field>
|
<field name="model">stock_co.warehouse_stock.start</field>
|
||||||
|
@ -53,7 +57,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||||
<field name="name">Warehouse Report</field>
|
<field name="name">Warehouse Report</field>
|
||||||
<field name="wiz_name">stock_co.warehouse_stock</field>
|
<field name="wiz_name">stock_co.warehouse_stock</field>
|
||||||
</record>
|
</record>
|
||||||
<menuitem parent="stock.menu_stock" sequence="120" icon="tryton-print"
|
<menuitem parent="menu_reports" sequence="120" icon="tryton-print"
|
||||||
action="wizard_warehouse_stock_report" id="warehouse_stock_report"/>
|
action="wizard_warehouse_stock_report" id="warehouse_stock_report"/>
|
||||||
|
|
||||||
<record model="ir.ui.view" id="print_products_start_view_form">
|
<record model="ir.ui.view" id="print_products_start_view_form">
|
||||||
|
@ -73,25 +77,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||||
<field name="name">Products Report</field>
|
<field name="name">Products Report</field>
|
||||||
<field name="wiz_name">stock_co.print_products</field>
|
<field name="wiz_name">stock_co.print_products</field>
|
||||||
</record>
|
</record>
|
||||||
<menuitem parent="stock.menu_stock" sequence="120" icon="tryton-print"
|
<menuitem parent="menu_reports" sequence="140" icon="tryton-print"
|
||||||
action="wizard_print_produts_report" id="print_products_report"/>
|
action="wizard_print_produts_report" id="print_products_report"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<record model="ir.ui.view" id="create_internal_shipment_start_view_form">
|
|
||||||
<field name="model">stock_co.create_internal_shipment.start</field>
|
|
||||||
<field name="type">form</field>
|
|
||||||
<field name="name">create_internal_shipment_form</field>
|
|
||||||
</record>
|
|
||||||
<record model="ir.action.wizard" id="act_create_internal_shipment">
|
|
||||||
<field name="name">Create Internal Shipment</field>
|
|
||||||
<field name="wiz_name">stock_co.create_internal_shipment</field>
|
|
||||||
</record>
|
|
||||||
<record model="ir.action.keyword" id="action_move_fix_number_keyword">
|
|
||||||
<field name="keyword">form_action</field>
|
|
||||||
<field name="model">stock.shipment.in,-1</field>
|
|
||||||
<field name="action" ref="act_create_internal_shipment"/>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
</tryton>
|
</tryton>
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||||
|
this repository contains the full copyright notices and license terms. -->
|
||||||
|
<form>
|
||||||
|
<label name="company"/>
|
||||||
|
<field name="company"/>
|
||||||
|
<label name="type_shipment"/>
|
||||||
|
<field name="type_shipment"/>
|
||||||
|
<label name="start_date"/>
|
||||||
|
<field name="start_date"/>
|
||||||
|
<label name="end_date"/>
|
||||||
|
<field name="end_date"/>
|
||||||
|
|
||||||
|
</form>
|
Loading…
Reference in New Issue