Merge pull request #5404 from expsa/feature/purchase-branch-correct-paths-20251113-144925

feat: add branch field to purchase modules with correct paths
This commit is contained in:
Mohamed Eltayar 2025-11-13 16:00:15 +03:00 committed by GitHub
commit 9000c4d360
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 3 deletions

View File

@ -124,6 +124,19 @@ class PurchaseOrderCustom(models.Model):
('budget_rejected', 'Rejected By Budget'), ('budget_rejected', 'Rejected By Budget'),
('wait_for_send', 'Waiting For Send to Budget')], default='wait') ('wait_for_send', 'Waiting For Send to Budget')], default='wait')
department_id = fields.Many2one('hr.department', compute="_compute_department_id", store=True, readonly=False) department_id = fields.Many2one('hr.department', compute="_compute_department_id", store=True, readonly=False)
branch_id = fields.Many2one(
'hr.department',
string='Branch',
compute='_compute_branch_id',
store=True,
readonly=True
)
branch_short_name = fields.Char(
string='Branch',
related='branch_id.branch_short_name',
store=True,
readonly=True
)
purpose = fields.Char() purpose = fields.Char()
category_ids = fields.Many2many('product.category', string='Categories') category_ids = fields.Many2many('product.category', string='Categories')
committe_members = fields.One2many('committe.member', inverse_name='po_id') committe_members = fields.One2many('committe.member', inverse_name='po_id')
@ -187,6 +200,16 @@ class PurchaseOrderCustom(models.Model):
for rec in self: for rec in self:
rec.department_id = rec.request_id.department_id rec.department_id = rec.request_id.department_id
@api.depends('request_id.branch_id', 'department_id.branch_name')
def _compute_branch_id(self):
for rec in self:
branch = False
if rec.request_id and rec.request_id.branch_id:
branch = rec.request_id.branch_id
elif rec.department_id and rec.department_id.branch_name:
branch = rec.department_id.branch_name
rec.branch_id = branch
def _recompute_all_department_id(self): def _recompute_all_department_id(self):
for rec in self.sudo().search([('request_id', '!=', False), ('department_id', '=', False)]): for rec in self.sudo().search([('request_id', '!=', False), ('department_id', '=', False)]):
rec._compute_department_id() rec._compute_department_id()

View File

@ -67,7 +67,7 @@
<field name="department_id" force_save="1" <field name="department_id" force_save="1"
attrs="{'readonly' : ['|',('state' , '!=' , 'draft'),('by_purchase' , '!=' , True)] , 'required' : [('by_purchase' , '=' , True)]}" attrs="{'readonly' : ['|',('state' , '!=' , 'draft'),('by_purchase' , '!=' , True)] , 'required' : [('by_purchase' , '=' , True)]}"
readonly="1"/> readonly="1"/>
<field name="branch_id" readonly="1"/> <field name="branch_id" readonly="1" context="{'show_branch_short': True}"/>
<field name="employee_id" attrs="{'readonly':[('by_purchase' , '=' , False)]}" required="1" <field name="employee_id" attrs="{'readonly':[('by_purchase' , '=' , False)]}" required="1"
options="{'no_create' : True , 'no_edit' : True ,'no_open' : True}"/> options="{'no_create' : True , 'no_edit' : True ,'no_open' : True}"/>
<field name="product_category_ids" widget="many2many_tags"/> <field name="product_category_ids" widget="many2many_tags"/>
@ -136,7 +136,7 @@
<field name="date"/> <field name="date"/>
<field name="employee_id"/> <field name="employee_id"/>
<field name="department_id"/> <field name="department_id"/>
<field name="branch_id"/> <field name="branch_id" context="{'show_branch_short': True}"/>
<field name="product_category_ids" widget="many2many_tags"/> <field name="product_category_ids" widget="many2many_tags"/>
<field name="state"/> <field name="state"/>
<field name="purchase_state_summary" optional="show"/> <field name="purchase_state_summary" optional="show"/>
@ -153,7 +153,7 @@
<field name="name" string="Request Number"/> <field name="name" string="Request Number"/>
<field name="employee_id" string="Employee"/> <field name="employee_id" string="Employee"/>
<field name="department_id" string="Department"/> <field name="department_id" string="Department"/>
<field name="branch_id" string="Branch"/> <field name="branch_id" string="Branch" context="{'show_branch_short': True}"/>
<field name="purchase_purpose" string="Purpose"/> <field name="purchase_purpose" string="Purpose"/>
<field name="partner_id" string="Vendor"/> <field name="partner_id" string="Vendor"/>

View File

@ -100,6 +100,10 @@
<field name="recommendation_order" string="Recommend Order"/> <field name="recommendation_order" string="Recommend Order"/>
</xpath> </xpath>
<xpath expr="//field[@name='department_id']" position="after">
<field name="branch_id" context="{'from_branch_field': True}"/>
</xpath>
</field> </field>
</record> </record>
@ -304,6 +308,7 @@
<!--here --> <!--here -->
<field name="purchase_cost" invisible="1"/> <field name="purchase_cost" invisible="1"/>
<field name="department_id" invisible="0"/> <field name="department_id" invisible="0"/>
<field name="branch_id" readonly="1" context="{'show_branch_short': True}"/>
<field name="purchase_request_employee_id"/> <field name="purchase_request_employee_id"/>
<field name="purpose" attrs="{'readonly': [('state','in',['done','cancel'])]}"/> <field name="purpose" attrs="{'readonly': [('state','in',['done','cancel'])]}"/>
</xpath> </xpath>