diff --git a/purchase_stock_flowchart/__manifest__.py b/purchase_stock_flowchart/__manifest__.py index 78b8975..f8641f2 100644 --- a/purchase_stock_flowchart/__manifest__.py +++ b/purchase_stock_flowchart/__manifest__.py @@ -5,7 +5,7 @@ "description": "This module enhances the Purchase Order by adding a flowchart that visually represents the stock flow, providing a clearer understanding of inventory movements associated with each order.", 'images': ['static/description/banner.png'], # 560x280 px "category": 'Inventory/Purchase', - "version": "0.0.2", + "version": "0.0.3", "license": "AGPL-3", "author": "Victor", "price": 0, diff --git a/purchase_stock_flowchart/models/purchase_order.py b/purchase_stock_flowchart/models/purchase_order.py index 76367fe..12a3ab8 100644 --- a/purchase_stock_flowchart/models/purchase_order.py +++ b/purchase_stock_flowchart/models/purchase_order.py @@ -24,13 +24,17 @@ def _get_purchase_picking_flowchart_graph(self, more_info=False): self._get_flowchart_element(more_info=more_info), self._get_flowchart_click() ] + i18n, menu_id = None, None + if self.picking_ids: + i18n = dict(self.env['stock.picking'].fields_get(allfields=['state'])['state']['selection']) + menu_id = self.env.ref('stock.menu_stock_root').id for hierarchy in self.picking_ids._get_picking_hierarchy(): if len(hierarchy) > 1: - flowchart.append(hierarchy[0]._get_flowchart_sub_graph()) + flowchart.append(hierarchy[0]._get_flowchart_sub_graph(i18n, menu_id)) flowchart.append(f'po{self.id} --> sub{hierarchy[0].id}') elif len(hierarchy) == 1: - flowchart.append(f'po{self.id} --> {hierarchy[0]._get_flowchart_element()}') - flowchart.append(hierarchy[0]._get_flowchart_click()) + flowchart.append(f'po{self.id} --> {hierarchy[0]._get_flowchart_element(i18n)}') + flowchart.append(hierarchy[0]._get_flowchart_click(menu_id)) return '\n'.join(flowchart) def _get_flowchart_style(self): @@ -64,7 +68,8 @@ def _get_flowchart_element(self, i18n=None, more_info=False): return f'po{self.id}("{self.name} - {_(i18n[self.state])}\n{self.partner_id.display_name}"):::{state}' return f'po{self.id}({self.name} - {_(i18n[self.state])}):::{state}' - def _get_flowchart_click(self): + def _get_flowchart_click(self, menu_id=None): self.ensure_one() - menu_id = self.env.ref('purchase.menu_purchase_root') - return f'click po{self.id} "/web#id={self.id}&model=purchase.order&view_type=form&menu_id={menu_id.id}" _blank' + if not menu_id: + menu_id = self.env.ref('purchase.menu_purchase_root').id + return f'click po{self.id} "/web#id={self.id}&model=purchase.order&view_type=form&menu_id={menu_id}" _blank' diff --git a/sale_stock_flowchart/__manifest__.py b/sale_stock_flowchart/__manifest__.py index b1b1087..b2e0f26 100644 --- a/sale_stock_flowchart/__manifest__.py +++ b/sale_stock_flowchart/__manifest__.py @@ -5,7 +5,7 @@ "description": "This module enhances the Sale Order by adding a flowchart that visually represents the stock flow, providing a clearer understanding of inventory movements associated with each order.", 'images': ['static/description/banner.png'], # 560x280 px "category": 'Sales/Sales', - "version": "0.0.2", + "version": "0.0.3", "license": "AGPL-3", "author": "Victor", "price": 0, diff --git a/sale_stock_flowchart/models/sale_order.py b/sale_stock_flowchart/models/sale_order.py index b027576..f9915fb 100644 --- a/sale_stock_flowchart/models/sale_order.py +++ b/sale_stock_flowchart/models/sale_order.py @@ -24,13 +24,17 @@ def _get_sale_picking_flowchart_graph(self, more_info=False): self._get_flowchart_element(more_info=more_info), self._get_flowchart_click() ] + i18n, menu_id = None, None + if self.picking_ids: + i18n = dict(self.env['stock.picking'].fields_get(allfields=['state'])['state']['selection']) + menu_id = self.env.ref('stock.menu_stock_root').id for hierarchy in self.picking_ids._get_picking_hierarchy(): if len(hierarchy) > 1: - flowchart.append(hierarchy[0]._get_flowchart_sub_graph()) + flowchart.append(hierarchy[0]._get_flowchart_sub_graph(i18n, menu_id)) flowchart.append(f'so{self.id} --> sub{hierarchy[0].id}') elif len(hierarchy) == 1: - flowchart.append(f'so{self.id} --> {hierarchy[0]._get_flowchart_element()}') - flowchart.append(hierarchy[0]._get_flowchart_click()) + flowchart.append(f'so{self.id} --> {hierarchy[0]._get_flowchart_element(i18n)}') + flowchart.append(hierarchy[0]._get_flowchart_click(menu_id)) return '\n'.join(flowchart) def _get_flowchart_style(self): @@ -63,7 +67,8 @@ def _get_flowchart_element(self, i18n=None, more_info=False): return f'so{self.id}("{self.name} - {_(i18n[self.state])}\n{self.partner_id.display_name}"):::{state}' return f'so{self.id}({self.name} - {_(i18n[self.state])}):::{state}' - def _get_flowchart_click(self): + def _get_flowchart_click(self, menu_id=None): self.ensure_one() - menu_id = self.env.ref('sale.sale_order_menu') - return f'click so{self.id} "/web#id={self.id}&model=sale.order&view_type=form&menu_id={menu_id.id}" _blank' + if not menu_id: + menu_id = self.env.ref('sale.sale_order_menu').id + return f'click so{self.id} "/web#id={self.id}&model=sale.order&view_type=form&menu_id={menu_id}" _blank' diff --git a/stock_flowchart/__manifest__.py b/stock_flowchart/__manifest__.py index 079ea92..ed69197 100644 --- a/stock_flowchart/__manifest__.py +++ b/stock_flowchart/__manifest__.py @@ -4,7 +4,7 @@ "summary": "Technical module that adds a generic flowchart to stock for use by other modules.", "description": "Technical module that adds a generic flowchart to stock for use by other modules.", "category": "Hidden", - "version": "0.0.1", + "version": "0.0.2", "license": "AGPL-3", "author": "Victor", "price": 0, diff --git a/stock_flowchart/models/stock_picking.py b/stock_flowchart/models/stock_picking.py index 5bab38f..b8f7f52 100644 --- a/stock_flowchart/models/stock_picking.py +++ b/stock_flowchart/models/stock_picking.py @@ -8,31 +8,35 @@ class StockPicking(models.Model): _inherit = 'stock.picking' - def _get_flowchart_sub_graph(self): + def _get_flowchart_sub_graph(self, i18n=None, menu_id=None): self.ensure_one() + if not i18n: + i18n = dict(self.env['stock.picking'].fields_get(allfields=['state'])['state']['selection']) + if not menu_id: + menu_id = self.env.ref('stock.menu_stock_root').id click_done = [] flowchart = [f'subgraph sub{self.id} [" "]', 'direction LR'] # Add all backorder parent recursively backorder = self while backorder.backorder_id: - flowchart.append(f'{backorder.backorder_id._get_flowchart_element()} --> {backorder._get_flowchart_element()}') + flowchart.append(f'{backorder.backorder_id._get_flowchart_element(i18n)} --> {backorder._get_flowchart_element(i18n)}') if backorder.backorder_id.id not in click_done: - flowchart.append(backorder.backorder_id._get_flowchart_click()) + flowchart.append(backorder.backorder_id._get_flowchart_click(menu_id)) click_done.append(backorder.backorder_id.id) if backorder.id not in click_done: - flowchart.append(backorder._get_flowchart_click()) + flowchart.append(backorder._get_flowchart_click(menu_id)) click_done.append(backorder.id) backorder = backorder.backorder_id # Add all backorder child recursively backorder = self while backorder.backorder_ids: for back in backorder.backorder_ids: - flowchart.append(f'{backorder._get_flowchart_element()} --> {back._get_flowchart_element()}') + flowchart.append(f'{backorder._get_flowchart_element(i18n)} --> {back._get_flowchart_element(i18n)}') if backorder.id not in click_done: - flowchart.append(backorder._get_flowchart_click()) + flowchart.append(backorder._get_flowchart_click(menu_id)) click_done.append(backorder.id) if back.id not in click_done: - flowchart.append(back._get_flowchart_click()) + flowchart.append(back._get_flowchart_click(menu_id)) click_done.append(back.id) backorder = back flowchart.append('end') @@ -85,7 +89,8 @@ def _get_flowchart_element(self, i18n=None): state = self._get_flowchart_state_color().get(self.state) return f'sp{self.id}({self.name} - {_(i18n[self.state])}):::{state}' - def _get_flowchart_click(self): + def _get_flowchart_click(self, menu_id=None): self.ensure_one() - stock_menu = self.env.ref('stock.menu_stock_root') - return f'click sp{self.id} "/web#id={self.id}&model=stock.picking&view_type=form&menu_id={stock_menu.id}" _blank' \ No newline at end of file + if not menu_id: + menu_id = self.env.ref('stock.menu_stock_root').id + return f'click sp{self.id} "/web#id={self.id}&model=stock.picking&view_type=form&menu_id={menu_id}" _blank' \ No newline at end of file