diff --git a/__init__.py b/__init__.py index 95e4b75..ab580de 100644 --- a/__init__.py +++ b/__init__.py @@ -35,6 +35,7 @@ def register(): shipment.ShipmentInternalForceDraft, shipment.Assign, inventory.CreateInventories, + shipment.ShipmentInForceDraft, module='stock_co', type_='wizard') Pool.register( stock.MoveByProduct, diff --git a/locale/es.po b/locale/es.po index 92f823c..c6bfc22 100644 --- a/locale/es.po +++ b/locale/es.po @@ -337,3 +337,7 @@ msgstr "Cancelar" msgctxt "wizard_button:stock_co.warehouse_stock_detailed,start,print_:" msgid "Print" msgstr "Imprimir" + +msgctxt "model:ir.action,name:shipment_in_force_draft" +msgid "Force Draft" +msgstr "Forzar a Borrador" diff --git a/shipment.py b/shipment.py index a8801bb..002f1de 100644 --- a/shipment.py +++ b/shipment.py @@ -309,6 +309,40 @@ class ShipmentInternalForceDraft(Wizard): return 'end' +class ShipmentInForceDraft(Wizard): + 'Shipment In Force Draft' + __name__ = 'stock.shipment.in.force_draft' + start_state = 'force_draft' + force_draft = StateTransition() + + def transition_force_draft(self): + shipment = Table('stock_shipment_in') + move = Table('stock_move') + id_shipment = Transaction().context['active_id'] + cursor = Transaction().connection.cursor() + if not id_shipment: + return 'end' + cursor.execute(*shipment.update( + columns=[shipment.state], + values=['draft'], + where=shipment.id == id_shipment) + ) + pool = Pool() + ShipmentIn = pool.get('stock.shipment.in') + shipmentin = ShipmentIn(id_shipment) + moves_ids = [m.id for m in shipmentin.inventory_moves] + cursor.execute(*move.delete( + where=move.id.in_(moves_ids)) + ) + moves_ids = [m.id for m in shipmentin.incoming_moves] + cursor.execute(*move.update( + columns=[move.state], + values=['draft'], + where=move.id.in_(moves_ids)) + ) + return 'end' + + class ShipmentDetailedStart(ModelView): 'Shipment Detailed Start' __name__ = 'stock.shipment.shipment_detailed.start' @@ -379,7 +413,7 @@ class ShipmentDetailedReport(Report): shipments_id = [model + ',' + str(sh['id']) for sh in shipments] fields_names = [ 'product.account_category.name', 'product.name', 'product.cost_price', - 'quantity', 'to_location.name' + 'quantity', 'to_location.name', 'from_location.name' ] fields = ModelShipment.fields_get(fields_names=['operation_center']) if 'operation_center' in fields.keys(): @@ -415,7 +449,7 @@ class ShipmentDetailedReport(Report): 'cost_price': cost_price, 'category': category, 'category_ad': category_ad, - 'cost_base': float(cost_price) * quantity, + 'cost_base': Decimal(str(round(float(cost_price) * quantity, 2))), } try: diff --git a/shipment.xml b/shipment.xml index bbfb5dd..9a1c725 100644 --- a/shipment.xml +++ b/shipment.xml @@ -5,7 +5,7 @@ this repository contains the full copyright notices and license terms. --> - + stock_co.create_internal_shipment.start form @@ -75,5 +75,15 @@ this repository contains the full copyright notices and license terms. --> + + + Force Draft + stock.shipment.in.force_draft + + + form_action + stock.shipment.in,-1 + + diff --git a/shipment_detailed.fods b/shipment_detailed.fods index 04b7f83..56ddd87 100644 Binary files a/shipment_detailed.fods and b/shipment_detailed.fods differ diff --git a/stock.py b/stock.py index 1db5119..bfc4540 100644 --- a/stock.py +++ b/stock.py @@ -31,12 +31,21 @@ class Move(metaclass=PoolMeta): description = fields.Char('Description', select=True, states=STATES_MOVE) current_stock = fields.Function(fields.Float('Current Stock', depends=['product']), 'on_change_with_current_stock') + reference = fields.Function(fields.Char('Reference', + depends=['product'], help='reference of product'), 'get_reference') @fields.depends('current_stock') def on_change_product(self, name=None): super(Move, self).on_change_product() self.current_stock = self.on_change_with_current_stock() + @fields.depends('product') + def get_reference(self, name=None): + reference = None + if self.product and hasattr(self.product, 'reference') and self.product.reference: + reference = self.product.reference + return reference + @fields.depends('product', 'from_location', 'to_location') def on_change_with_current_stock(self, name=None): res = 0 diff --git a/view/move_form.xml b/view/move_form.xml index d7133c8..11e339a 100644 --- a/view/move_form.xml +++ b/view/move_form.xml @@ -7,6 +7,8 @@ this repository contains the full copyright notices and license terms. -->