Merge pull request #5396 from expsa/feature/add-branch-field-purchase-request-20251113-104552

feat: Add Branch Field to Purchase Request
This commit is contained in:
Mohamed Eltayar 2025-11-13 11:02:34 +03:00 committed by GitHub
commit 0434e7f892
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 32 deletions

View File

@ -1946,6 +1946,11 @@ msgstr "أوامر الشراء المبدئية"
msgid "Request id"
msgstr ""
#. module: purchase_requisition_custom
#: model:ir.model.fields,field_description:purchase_requisition_custom.field_purchase_request__branch_id
msgid "Branch"
msgstr "الفرع"
#. module: purchase_requisition_custom
#: model:ir.model.fields,field_description:purchase_requisition_custom.field_purchase_request__by_purchase
msgid "Requested by Purchase"

View File

@ -48,6 +48,7 @@ class PurchaseRequest(models.Model):
name = fields.Char(string='Name', copy=False, default=lambda self: '/')
employee_id = fields.Many2one(comodel_name='hr.employee', string='Employee', default=lambda s: s._default_emp().id)
department_id = fields.Many2one('hr.department', 'Department')
branch_id = fields.Many2one('hr.department', string='Branch', compute='_compute_branch_id', store=True, readonly=True)
line_ids = fields.One2many(comodel_name='purchase.request.line', inverse_name='request_id', copy=True)
date = fields.Date(string='Date', default=fields.Date.context_today, copy=False)
state = fields.Selection(
@ -91,6 +92,15 @@ class PurchaseRequest(models.Model):
)
has_approve_reject_permission = fields.Boolean(compute='_compute_permissions')
@api.depends('employee_id.department_id.branch_name', 'department_id.branch_name')
def _compute_branch_id(self):
for rec in self:
branch = False
if rec.employee_id and rec.employee_id.department_id:
branch = rec.employee_id.department_id.branch_name
elif rec.department_id:
branch = rec.department_id.branch_name
rec.branch_id = branch
def _compute_permissions(self):
for rec in self:
@ -409,9 +419,3 @@ class Employee(models.Model):
return result
else:
return super(Employee, self).name_get()
class ProductTempInherit(models.Model):
_inherit = 'product.template'
asset_ok = fields.Boolean(string="Asset Expensed")

View File

@ -67,6 +67,7 @@
<field name="department_id" force_save="1"
attrs="{'readonly' : ['|',('state' , '!=' , 'draft'),('by_purchase' , '!=' , True)] , 'required' : [('by_purchase' , '=' , True)]}"
readonly="1"/>
<field name="branch_id" readonly="1"/>
<field name="employee_id" attrs="{'readonly':[('by_purchase' , '=' , False)]}" required="1"
options="{'no_create' : True , 'no_edit' : True ,'no_open' : True}"/>
<field name="product_category_ids" widget="many2many_tags"/>
@ -95,7 +96,7 @@
<field name="line_ids" attrs="{'readonly':[('state' , '!=' , 'draft')]}">
<tree editable="bottom">
<field name="product_id"
domain="['|', ('purchase_ok', '=', True), ('asset_ok', '=', True)]"
domain="[('purchase_ok', '=', True)]"
options="{'no_create' : True , 'no_edit' : True ,'no_open' : True}"
optional="show"
required="1"/>
@ -135,6 +136,7 @@
<field name="date"/>
<field name="employee_id"/>
<field name="department_id"/>
<field name="branch_id"/>
<field name="product_category_ids" widget="many2many_tags"/>
<field name="state"/>
<field name="purchase_state_summary" optional="show"/>
@ -148,27 +150,19 @@
<field name="model">purchase.request</field>
<field name="arch" type="xml">
<search string="Purchase Request">
<!-- حقول البحث الأساسية -->
<field name="name" string="Request Number"/>
<field name="employee_id" string="Employee"/>
<field name="department_id" string="Department"/>
<field name="branch_id" string="Branch"/>
<field name="purchase_purpose" string="Purpose"/>
<field name="partner_id" string="Vendor"/>
<!-- البحث بالمنتجات - الهدف الأساسي -->
<field name="line_ids" string="Products"
filter_domain="[('line_ids.product_id.name', 'ilike', self)]"/>
<!-- البحث بفئات المنتجات -->
<field name="product_category_ids" string="Product Categories"/>
<!-- البحث بالتاريخ -->
<field name="date" string="Request Date"/>
<!-- البحث بالملاحظات -->
<field name="note" string="Notes"/>
<!-- فلاتر سريعة حسب الحالة -->
<separator/>
<filter string="Draft" name="draft" domain="[('state','=','draft')]"/>
<filter string="Direct Manager Approval" name="direct_manager" domain="[('state','=','direct_manager')]"/>
@ -178,7 +172,6 @@
<filter string="Refused" name="refuse" domain="[('state','=','refuse')]"/>
<separator/>
<!-- فلاتر مفيدة للعمل -->
<filter string="My Requests" name="my_requests"
domain="[('employee_id.user_id','=',uid)]"/>
<filter string="My Department" name="my_department"
@ -189,40 +182,26 @@
domain="[('state','in',['waiting'])]"/>
<separator/>
<!-- فلاتر حسب نوع الطلب -->
<filter string="Project Requests" name="project_type"
domain="[('type','=','project')]"/>
<filter string="Operational Requests" name="operational_type"
domain="[('type','=','operational')]"/>
<separator/>
<!-- فلاتر حسب وجود المورد -->
<filter string="With Vendor" name="with_vendor"
domain="[('partner_id','!=',False)]"/>
<filter string="Without Vendor" name="without_vendor"
domain="[('partner_id','=',False)]"/>
<separator/>
<!-- فلاتر زمنية -->
<filter string="Today" name="today"
domain="[('date','=',context_today())]"/>
<filter string="This Week" name="this_week"
domain="[('date','&gt;=',context_today() - datetime.timedelta(days=7))]"/>
<filter string="This Month" name="this_month"
domain="[('date','&gt;=',context_today() - datetime.timedelta(days=30))]"/>
<!-- تجميع منطقي -->
<group expand="0" string="Group By">
<filter string="State" name="group_state" context="{'group_by':'state'}"/>
<filter string="Employee" name="group_employee" context="{'group_by':'employee_id'}"/>
<filter string="Department" name="group_department" context="{'group_by':'department_id'}"/>
<filter string="Branch" name="group_branch" context="{'group_by':'branch_id'}"/>
<filter string="Vendor" name="group_vendor" context="{'group_by':'partner_id'}"/>
<filter string="Request Type" name="group_type" context="{'group_by':'type'}"/>
<filter string="Product Categories" name="group_categories" context="{'group_by':'product_category_ids'}"/>
<separator/>
<filter string="Request Date" name="group_date" context="{'group_by':'date'}"/>
<filter string="Month" name="group_month" context="{'group_by':'date:month'}"/>
<filter string="Year" name="group_year" context="{'group_by':'date:year'}"/>
</group>
</search>
</field>