Merge pull request #3837 from expsa/kchy_dev_odex25_purchase

IMP requestion cycle
This commit is contained in:
kchyounes19 2025-07-09 15:39:32 +01:00 committed by GitHub
commit 83dc4e5775
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 20 deletions

View File

@ -103,7 +103,6 @@ class PurchaseOrderCustom(models.Model):
('wait', 'Waiting To Be Signed'),
('unsign', 'UnSign'),
('sign', 'Sign'),
('sent_budget_waiting', 'Waiting For Sent Budget'),
('waiting', 'Waiting For Budget Confirmation'),
('draft', 'RFQ'),
('sent', 'RFQ Sent'),
@ -164,7 +163,7 @@ class PurchaseOrderCustom(models.Model):
# Domain 2 logic
domain2_met = (record.has_requisition) or \
(record.state not in ('wait', 'sent', 'sent_budget_waiting')) or \
(record.state not in ('wait', 'sent')) or \
(not record.is_purchase_budget)
# Combined logic: Domain1 OR (Domain2 AND state != 'sign')
if (domain1_met and record.has_requisition) or (domain2_met and record.state != 'sign'):
@ -469,7 +468,7 @@ class PurchaseOrderCustom(models.Model):
line.account_analytic_id = line.department_name.analytic_account_id
def button_draft(self):
self.write({'state': 'wait'})
self.write({'state': 'wait','is_signed': False})
def button_cancel(self):
for order in self:
@ -610,7 +609,7 @@ class PurchaseOrderCustom(models.Model):
""" Skip purchase budget"""
_logger.info("\n\n\n Skip Purchase Budget \n\n\n")
for po_id in self:
if po_id.state in ('sent', 'wait') or po_id.request_id:
if po_id.state in ('sent', 'wait', 'sign') or po_id.request_id:
# Deal with double validation process
valid_amount = self.env.user.company_id.currency_id.compute(
po_id.company_id.po_double_validation_amount, po_id.currency_id)
@ -755,6 +754,7 @@ class PurchaseOrderCustom(models.Model):
def button_confirm(self):
for order in self:
if order.requisition_id and order.requisition_type_exclusive == 'exclusive':
order.requisition_id.state = 'done'
other_orders = order.requisition_id.purchase_ids.filtered(
lambda po: po.id != order.id and po.state not in ['cancel', 'done']
)

View File

@ -239,22 +239,25 @@ class PurchaseRequisitionCustom(models.Model):
def action_skip_purchase_budget(self):
""" Skip purchase budget"""
purchase_orders = self.env['purchase.order'].search([('requisition_id', '=', self.id), ])
purchase_orders = self.env['purchase.order'].search([('requisition_id', '=', self.id),('state','=','sign')])
for po_id in purchase_orders:
# Deal with double validation process
valid_amount = self.env.user.company_id.currency_id.compute(po_id.company_id.po_double_validation_amount,
po_id.currency_id)
if po_id.company_id.po_double_validation == 'one_step' or (
po_id.company_id.po_double_validation == 'two_step' and po_id.amount_total > valid_amount):
po_id.write({'state': 'to approve'})
self.write({'state': 'checked'})
else:
if po_id.email_to_vendor:
po_id.write({'state': 'sent'})
else:
po_id.write({'state': 'draft'})
po_id.write({'send_to_budget': False})
self.write({'state': 'approve'})
po_id.write({'state': 'to approve'})
self.write({'state': 'checked'})
po_id.write({'send_to_budget': False})
# if po_id.company_id.po_double_validation == 'one_step' or (
# po_id.company_id.po_double_validation == 'two_step' and po_id.amount_total > valid_amount):
# po_id.write({'state': 'to approve'})
# self.write({'state': 'checked'})
# else:
# if po_id.email_to_vendor:
# po_id.write({'state': 'sent'})
# else:
# po_id.write({'state': 'draft'})
# po_id.write({'send_to_budget': False})
# self.write({'state': 'approve'})
def _compute_days(self):
self.days_count = _("Unknown")
@ -339,6 +342,9 @@ class PurchaseRequisitionCustom(models.Model):
def action_approve(self):
purchase_orders = self.env['purchase.order'].search(
[('requisition_id', '=', self.id), ('state', '=', 'to approve')])
cancel_orders = self.env['purchase.order'].search([('requisition_id', '=', self.id), ('state', 'not in', ['to approve','cancel','done'])])
# order.requisition_type_exclusive == 'exclusive':
cancel_orders.button_cancel()
po_order_approval = self.env.company.po_double_validation == 'two_step'
for po_id in purchase_orders:
# Deal with double validation process for first approve
@ -372,7 +378,7 @@ class PurchaseRequisitionCustom(models.Model):
def second_approval(self):
purchase_orders = self.env['purchase.order'].search([('requisition_id', '=', self.id)])
purchase_orders = self.env['purchase.order'].search([('requisition_id', '=', self.id), ('state', '=', 'to approve')])
po_order_approval = self.env.company.po_double_validation == 'two_step'
for po_id in purchase_orders:
# Deal with double validation process for second_approve
@ -399,7 +405,7 @@ class PurchaseRequisitionCustom(models.Model):
self.write({'state': 'approve'})
def third_approve(self):
purchase_orders = self.env['purchase.order'].search([('requisition_id', '=', self.id)])
purchase_orders = self.env['purchase.order'].search([('requisition_id', '=', self.id), ('state', '=', 'to approve')])
for po_id in purchase_orders:
if po_id.email_to_vendor:
po_id.write({'state': 'sent'})

View File

@ -163,8 +163,9 @@
'|', ('state','in',['sign','purchase','to approve','done',
'cancel','budget_rejected','wait_for_send','waiting']), ('is_signed', '=', True)]}"
string="Sign"/>
<button type="object" name="action_approve_po" string="Confirm Purchase" class="oe_highlight"
attrs="{'invisible':['|',('requisition_id','=',False),'|','&amp;',('requisition_type_exclusive', '!=','exclusive'),('is_purchase_budget','=',False),('state','not in',('to approve'))]}"/>
<!-- <button type="object" name="action_approve_po" string="Confirm Purchase" class="oe_highlight"-->
<!-- attrs="{'invisible':['|',('requisition_id','=',False),'|','&amp;',('requisition_type_exclusive', '!=','exclusive'),('is_purchase_budget','=',False),('state','not in',('to approve'))]}"/>-->
<button type="object" name="action_approve_po" string="Confirm Purchase" class="oe_highlight" invisible="1"/>
<button type="object" name="action_select" groups="purchase_requisition_custom.committe_member"
attrs="{'invisible':['|', '|',('state','in',['done','purchase','waiting','cancel']),('already_voted','=',True),('can_committee_vote', '=', False)]}"