From 1e9443d8a0b2fdddb1e1adaa30d37759da2b9f81 Mon Sep 17 00:00:00 2001 From: Samir Ladoui Date: Tue, 25 Feb 2025 17:08:51 +0100 Subject: [PATCH] [UPD] purchase_requisition_custom: retrieve department from purchase requst to purchase order --- .../purchase_requisition_custom/__manifest__.py | 1 + .../data/server_actions.xml | 11 +++++++++++ .../models/purchase_order.py | 14 ++++++++++++-- 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 odex25_purchase/purchase_requisition_custom/data/server_actions.xml diff --git a/odex25_purchase/purchase_requisition_custom/__manifest__.py b/odex25_purchase/purchase_requisition_custom/__manifest__.py index fd127f463..fff3759f1 100644 --- a/odex25_purchase/purchase_requisition_custom/__manifest__.py +++ b/odex25_purchase/purchase_requisition_custom/__manifest__.py @@ -14,6 +14,7 @@ 'data/purchase_sequence.xml', 'data/purchase_request_seq.xml', 'data/cron_data.xml', + 'data/server_actions.xml', 'views/purchase_requisition_custom.xml', 'views/purchase_request.xml', 'views/res_setting.xml', diff --git a/odex25_purchase/purchase_requisition_custom/data/server_actions.xml b/odex25_purchase/purchase_requisition_custom/data/server_actions.xml new file mode 100644 index 000000000..8af0e6846 --- /dev/null +++ b/odex25_purchase/purchase_requisition_custom/data/server_actions.xml @@ -0,0 +1,11 @@ + + + + + Compute Department for Purchase Orders + + code + env['purchase.order']._recompute_all_department_id() + + + diff --git a/odex25_purchase/purchase_requisition_custom/models/purchase_order.py b/odex25_purchase/purchase_requisition_custom/models/purchase_order.py index 032e8a278..0a069521d 100644 --- a/odex25_purchase/purchase_requisition_custom/models/purchase_order.py +++ b/odex25_purchase/purchase_requisition_custom/models/purchase_order.py @@ -83,7 +83,7 @@ class PurchaseOrderCustom(models.Model): ('cancel', 'Cancelled'), ('budget_rejected', 'Rejected By Budget'), ('wait_for_send', 'Waiting For Send to Budget')], default='wait') - department_id = fields.Many2one('hr.department') + department_id = fields.Many2one('hr.department', compute="_compute_department_id", store=True, readonly=False) purpose = fields.Char() category_ids = fields.Many2many('product.category', string='Categories') committe_members = fields.One2many('committe.member', inverse_name='po_id') @@ -120,6 +120,17 @@ class PurchaseOrderCustom(models.Model): is_signed = fields.Boolean() budget_id = fields.Many2one('crossovered.budget') already_voted = fields.Boolean(compute="_compute_already_voted") + + + @api.depends('request_id') + def _compute_department_id(self): + for rec in self: + rec.department_id = rec.request_id.department_id + + def _recompute_all_department_id(self): + for rec in self.sudo().search([('request_id', '!=', False), ('department_id', '=', False)]): + rec._compute_department_id() + def get_attachments(self): # Check if multiple records are passed, and handle them in a loop if len(self) > 1: @@ -188,7 +199,6 @@ class PurchaseOrderCustom(models.Model): return action - def _prepare_invoice(self): res = super(PurchaseOrderCustom, self)._prepare_invoice() res.update({'purchase_id': self.id, 'res_id': self.id,'res_model': 'purchase.order'})