diff --git a/__init__.py b/__init__.py index 981f658..0ee811d 100644 --- a/__init__.py +++ b/__init__.py @@ -16,10 +16,12 @@ def register(): shipment.InternalShipment, stock.WarehouseStockStart, stock.Inventory, - stock.ShipmentInternal, + # stock.ShipmentInternal, + shipment.ShipmentDetailedStart, stock.PrintProductsStart, module='stock_co', type_='model') Pool.register( + shipment.ShipmentDetailed, stock.PrintMoveByProduct, shipment.CreateInternalShipment, stock.WarehouseStock, @@ -29,6 +31,7 @@ def register(): module='stock_co', type_='wizard') Pool.register( stock.MoveByProduct, + shipment.ShipmentDetailedReport, stock.WarehouseReport, stock.PrintProductsReport, module='stock_co', type_='report') diff --git a/shipment.py b/shipment.py index 00b17bb..9ae43e3 100644 --- a/shipment.py +++ b/shipment.py @@ -1,17 +1,35 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. from datetime import date +from decimal import Decimal from sql import Table 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.model import ModelView, fields +from trytond.report import Report +from trytond.pyson import Eval class InternalShipment(metaclass=PoolMeta): 'Internal Shipment' __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 def wait(cls, shipments): super(InternalShipment, cls).wait(shipments) @@ -28,6 +46,64 @@ class InternalShipment(metaclass=PoolMeta): if 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): 'Create Internal Shipment Start' @@ -140,3 +216,78 @@ class ShipmentInternalForceDraft(Wizard): shipment.state = 'draft' shipment.save() 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 diff --git a/shipment.xml b/shipment.xml index ad41b48..dc02469 100644 --- a/shipment.xml +++ b/shipment.xml @@ -3,6 +3,22 @@ this repository contains the full copyright notices and license terms. --> + + + stock_co.create_internal_shipment.start + form + create_internal_shipment_form + + + Create Internal Shipment + stock_co.create_internal_shipment + + + form_action + stock.shipment.in,-1 + + + Shipment Out Force Draft stock.shipment.out.force_draft @@ -22,6 +38,26 @@ this repository contains the full copyright notices and license terms. --> stock.shipment.internal,-1 - + + + stock.shipment.shipment_detailed.start + form + print_shipment_detailed_start_form + + + Print Shipment Detailed + stock.shipment.shipment_detailed + + + + Shipment Detailed + + stock.shipment.shipment_detailed.report + stock_co/purchase_detailed.ods + ods + True + + diff --git a/shipment_detailed.fods b/shipment_detailed.fods new file mode 100644 index 0000000..78ff720 Binary files /dev/null and b/shipment_detailed.fods differ diff --git a/stock.py b/stock.py index 95dfc74..29c7fc6 100644 --- a/stock.py +++ b/stock.py @@ -539,65 +539,3 @@ class Inventory(metaclass=PoolMeta): InventoryLine.create(lines_to_create.values()) 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 diff --git a/stock.xml b/stock.xml index 2d0cd25..22c7e26 100644 --- a/stock.xml +++ b/stock.xml @@ -33,8 +33,12 @@ this repository contains the full copyright notices and license terms. --> Move by Product stock_co.print_move_by_product - + + + + stock_co.warehouse_stock.start @@ -53,7 +57,7 @@ this repository contains the full copyright notices and license terms. --> Warehouse Report stock_co.warehouse_stock - @@ -73,25 +77,7 @@ this repository contains the full copyright notices and license terms. --> Products Report stock_co.print_products - - - - - - stock_co.create_internal_shipment.start - form - create_internal_shipment_form - - - Create Internal Shipment - stock_co.create_internal_shipment - - - form_action - stock.shipment.in,-1 - - - diff --git a/view/print_shipment_detailed_start_form.xml b/view/print_shipment_detailed_start_form.xml new file mode 100644 index 0000000..af076d9 --- /dev/null +++ b/view/print_shipment_detailed_start_form.xml @@ -0,0 +1,14 @@ + + +
+