IMP purchase cycle

This commit is contained in:
younes 2025-06-25 16:03:12 +01:00
parent 79f8120c78
commit ea4f8df5d8
4 changed files with 97 additions and 113 deletions

View File

@ -48,19 +48,19 @@
</xpath>
<xpath expr="//button[@name='button_confirm']" position="attributes">
<attribute name="attrs">
{'invisible':[('state', 'in', ('wait', 'sent')),
('is_purchase_budget', '=', True)]}
</attribute>
</xpath>
<!-- <xpath expr="//button[@name='button_confirm']" position="attributes">-->
<!-- <attribute name="attrs">-->
<!-- {'invisible':[('state', 'in', ('wait', 'sent')),-->
<!-- ('is_purchase_budget', '=', True)]}-->
<!-- </attribute>-->
<!-- </xpath>-->
<xpath expr="//button[@name='button_confirm'][1]" position="attributes">
<attribute name="attrs">
{'invisible':[('state', 'in', ('wait', 'sent')),
('is_purchase_budget', '=', True)]}
</attribute>
</xpath>
<!-- <xpath expr="//button[@name='button_confirm'][1]" position="attributes">-->
<!-- <attribute name="attrs">-->
<!-- {'invisible':[('state', 'in', ('wait', 'sent')),-->
<!-- ('is_purchase_budget', '=', True)]}-->
<!-- </attribute>-->
<!-- </xpath>-->
</field>
</record>

View File

@ -22,7 +22,8 @@ class BudgetConfirmationCustom(models.Model):
rec.po_id.write({'state': 'budget_rejected'})
body = _(
"Purchase Order %s is Rejected By : %s With Reject Reason : %s" % (
str(rec.name), str(rec.env.user.name), str(rec.reject_reason or self.env.context.get('reject_reason',''))))
str(rec.name), str(rec.env.user.name),
str(rec.reject_reason or self.env.context.get('reject_reason', ''))))
# Send Notifications
subject = _('Reject Purchase Order')
author_id = rec.env.user.partner_id.id or None
@ -32,7 +33,8 @@ class BudgetConfirmationCustom(models.Model):
rec.request_id.write({'state': 'refuse'})
body = _(
"Purchase Request %s is Rejected By : %s With Reject Reason : %s" % (
str(rec.name), str(rec.env.user.name), str(rec.reject_reason or self.env.context.get('reject_reason',''))))
str(rec.name), str(rec.env.user.name),
str(rec.reject_reason or self.env.context.get('reject_reason', ''))))
# Send Notifications
subject = _('Reject Purchase Request Budget Confirmation')
author_id = rec.env.user.partner_id.id or None
@ -59,12 +61,16 @@ class BudgetConfirmationCustom(models.Model):
if self.po_id.requisition_id and self.po_id.requisition_type_exclusive == 'exclusive':
self.po_id.requisition_id.write({'state': 'checked'})
if self.po_id:
self.po_id.write({'state': 'to approve'})
if self.po_id.requisition_id:
self.po_id.write({'state': 'to approve'})
else:
self.po_id.write({'state': 'draft'})
if self.request_id and self.type == 'purchase.request':
# Update reserve of budget_lines
self.request_id.write({'state': 'waiting'})
class CrossoveredBudgetLines(models.Model):
_inherit = "crossovered.budget.lines"
budget_confirm_line_ids = fields.One2many('budget.confirmation.line', 'budget_line_id', 'Confirmation')
budget_confirm_line_ids = fields.One2many('budget.confirmation.line', 'budget_line_id', 'Confirmation')

View File

@ -439,8 +439,8 @@ class PurchaseOrderCustom(models.Model):
# return res
def print_quotation(self):
if self.state in ['wait']:
self.write({'state': "sent"})
# if self.state in ['wait']:
# self.write({'state': "sent"})
return self.env.ref('purchase.report_purchase_quotation').report_action(self)
def action_rfq_send(self):
@ -477,26 +477,24 @@ 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 ('wait_for_send', 'wait', 'sign') or po_id.request_id:
if po_id.state in ('sent', 'wait') 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)
# second_amount = self.env.user.company_id.currency_id.compute(po_id.company_id.second_approve, po_id.currency_id)
_logger.info("\n\n\n Purchase state inside if 1 \n\n\n")
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):
if po_id.company_id.po_double_validation == 'two_step' and po_id.amount_total > valid_amount:
_logger.info("\n\n\n Purchase state inside if 2 \n\n\n")
po_id.write({'state': 'to approve'})
else:
_logger.info("\n\n\n Purchase state inside else1 \n\n\n")
if po_id.email_to_vendor:
_logger.info("\n\n\n Purchase state inside if 3 \n\n\n")
po_id.write({'state': 'sent'})
else:
_logger.info("\n\n\n Purchase state inside else2 \n\n\n")
po_id.write({'state': 'draft'})
# if not po_id.email_to_vendor:
# _logger.info("\n\n\n Purchase state inside if 3 \n\n\n")
# po_id.write({'state': 'sent'})
# else:
_logger.info("\n\n\n Purchase state inside else2 \n\n\n")
po_id.write({'state': 'draft'})
_logger.info("\n\n\n Send to budet = false \n\n\n")
po_id.write({'send_to_budget': False})

View File

@ -109,7 +109,7 @@
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field eval="100" name="priority"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='button_box']" position="inside">
<xpath expr="//div[@name='button_box']" position="inside">
<button name="get_attachments" type="object"
class="oe_stat_button"
icon="fa-file-text-o">
@ -117,10 +117,9 @@
</button>
</xpath>
<xpath expr="//field[@name='payment_term_id']" position="after">
<field invisible="1" readonly="1" name='res_model'/>
<field invisible="1" readonly="1" name='res_id'/>
<field invisible="1" readonly="1" name='res_model'/>
<field invisible="1" readonly="1" name='res_id'/>
</xpath>
<xpath expr="//div[hasclass('oe_button_box')]" position="inside">
<button class="oe_stat_button" name="open_confirmation" type="object" string="Budget Confirmation"
icon="fa-list-ol" groups="purchase.group_purchase_manager"/>
@ -130,9 +129,28 @@
</xpath>
<field name="partner_id" position="attributes">
<attribute name="options">{'no_create': True, 'no_open': True}</attribute>
<attribute name="domain">['&amp;',('supplier_rank','>', 0),'|', ('company_id', '=', False), ('company_id', '=', company_id)]</attribute>
<attribute name="domain">['&amp;',('supplier_rank','>', 0),'|', ('company_id', '=', False),
('company_id', '=', company_id)]
</attribute>
</field>
<xpath expr="/form/header/button[@name='action_rfq_send']" position="after">
<xpath expr="/form/header/button[@name='action_rfq_send'][1]" position="attributes">
<attribute name="states">wait</attribute>
<attribute name="groups">purchase.group_purchase_manager, purchase.group_purchase_user</attribute>
</xpath>
<xpath expr="/form/header/button[@name='action_rfq_send'][2]" position="attributes">
<attribute name="groups">purchase.group_purchase_manager, purchase.group_purchase_user</attribute>
</xpath>
<xpath expr="/form/header/button[@name='action_rfq_send'][3]" position="attributes">
<attribute name="groups">purchase.group_purchase_manager, purchase.group_purchase_user</attribute>
</xpath>
<xpath expr="/form/header/button[@name='print_quotation'][1]" position="attributes">
<attribute name="groups">purchase.group_purchase_manager, purchase.group_purchase_user</attribute>
<attribute name="states">wait</attribute>
</xpath>
<xpath expr="/form/header/button[@name='print_quotation'][2]" position="attributes">
<attribute name="groups">purchase.group_purchase_manager, purchase.group_purchase_user</attribute>
</xpath>
<xpath expr="/form/header/button[@name='print_quotation']" position="after">
<field name="parent_state" invisible="1"/>
<field name="already_voted" invisible="1"/>
<field name="requisition_state" invisible="1"/>
@ -152,7 +170,8 @@
<button type="object" name="action_refuse" groups="purchase_requisition_custom.committe_member"
attrs="{'invisible':['|',('state','in',['done','purchase','waiting','cancel']),('already_voted','=',True)]}"
string="Refuse"/>
<button type="object" name="action_recommend" groups="purchase_requisition_custom.group_select_recommended_offer"
<button type="object" name="action_recommend"
groups="purchase_requisition_custom.group_select_recommended_offer"
confirm="Are you sure you want to process ?"
attrs="{'invisible':['|',
('recommendation_order','=', True),('purchase_commitee', '=', False)]}" string="Recommended"/>
@ -165,55 +184,52 @@
<button type="object" name="action_budget" string="Send To Budget Check" class="oe_highlight"
attrs="{'invisible':['|',('requisition_id','!=',False),'|',('state','not in',('wait','sent')),('is_purchase_budget','=',False)]}"/>
<button name="action_skip_budget" type="object" string="Skip Budget"
attrs="{'invisible':['|',('requisition_id','!=',False),'|',('state','not in',('wait','sent')),('is_purchase_budget','=',False)]}"
attrs="{'invisible':['|',('requisition_id','!=',False),'|',('state','not in',('wait')),('is_purchase_budget','=',False)]}"
groups="purchase_requisition_custom.group_skip_purchase_budget"/>
<button name="action_skip_budget" type="object" string="Skip Budget" class="oe_highlight"
attrs="{'invisible':['|',('requisition_id','!=',False),'|',('state','not in',('sent')),('is_purchase_budget','=',False)]}"
groups="purchase_requisition_custom.group_skip_purchase_budget"/>
<!-- <button name="button_draft" states="cancel" string="Set to Draft" type="object"/>-->
</xpath>
<xpath expr="//button[@name='button_approve']" position="replace">
<button name="button_approve" type="object" attrs="{'invisible':['|',('requisition_id','!=',False),('state','not in',('to approve'))]}" string="Approve Order" class="oe_highlight" groups="purchase.group_purchase_manager"/>
<button name="button_approve" type="object"
attrs="{'invisible':['|',('requisition_id','!=',False),('state','not in',('to approve'))]}"
string="Approve Order" class="oe_highlight" groups="purchase.group_purchase_manager"/>
</xpath>
<xpath expr="//button[@name='button_draft']" position="after">
<button string='PO To Contract' name="open_convert_po_contract" type="object"
class="oe_highlight" groups="purchase.group_purchase_manager"
attrs="{'invisible':[('state','in',('draft','wait','wait_for_send','sent','to approve','sign','waiting','purchase','cancel'))]}"/>
</xpath>
<xpath expr="//button[@name='button_draft']" position="attributes">
<attribute name="class">oe_highlight</attribute>
</xpath>
<xpath expr="//field[@name='date_order']" position="after">
<field name="type"/>
</xpath>
<!-- <xpath expr="/form/header/button[@id='draft_confirm']" position="attributes">-->
<!-- <attribute name="groups">purchase.group_purchase_manager</attribute>-->
<!-- <attribute name="states">""</attribute>-->
<!-- <attribute name="attrs">-->
<!-- {'invisible':[('state','in',('wait','wait_for_send','sign','sent','to approve','waiting','purchase','cancel'))]}-->
<!-- </attribute>-->
<!-- </xpath>-->
<xpath expr="/form/header/button[@id='draft_confirm']" position="attributes">
<attribute name="groups">purchase.group_purchase_manager</attribute>
<attribute name="states">""</attribute>
<attribute name="attrs">
{'invisible':[('state','in',('wait','wait_for_send','sign','sent','to approve','waiting','purchase','cancel'))]}
</attribute>
<attribute name="states">draft</attribute>
<attribute name="class">oe_highlight</attribute>
</xpath>
<!-- ('is_purchase_budget', '=', False)-->
<xpath expr="/form/header/button[@id='bid_confirm']" position="attributes">
<attribute name="states">""</attribute>
<attribute name="attrs">
{'invisible':['|',('state','in',('draft','wait_for_send','waiting','purchase','cancel')),('is_purchase_budget','=',True)]}
{'invisible':['|',('state','not in',('sent','wait')),('is_purchase_budget','=',True)]}
</attribute>
</xpath>
<xpath expr="/form/header/button[@name='action_rfq_send']" position="attributes">
<attribute name="groups">purchase.group_purchase_manager</attribute>
</xpath>
<xpath expr="/form/header/button[@name='action_rfq_send'][1]" position="attributes">
<attribute name="states">wait,wait_for_send</attribute>
</xpath>
<xpath expr="/form/header/button[@name='print_quotation']" position="attributes">
<attribute name="groups">purchase.group_purchase_manager</attribute>
<attribute name="states">wait,wait_for_send</attribute>
</xpath>
<xpath expr="/form/header/button[@name='button_cancel']" position="attributes">
<attribute name="groups">purchase.group_purchase_manager</attribute>
</xpath>
<xpath expr="/form/header/button[@name='button_cancel']" position="attributes">
<attribute name="states">draft,wait,to approve,sent,purchase,wait_for_send</attribute>
</xpath>
@ -229,22 +245,18 @@
<xpath expr="//field[@name='origin']" position="attributes">
<attribute name="attrs">{'readonly':[('state','in',('done','cancel','waiting'))]}</attribute>
</xpath>
<xpath expr="//field[@name='payment_term_id']" position="attributes">
<attribute name="attrs">{'readonly':[('state','in',('waiting','done','cancel'))]}</attribute>
</xpath>
<xpath expr="//field[@name='fiscal_position_id']" position="attributes">
<attribute name="attrs">{'readonly':[('state','in',('done','waiting','cancel'))]}</attribute>
</xpath>
<xpath expr="//field[@name='order_line']/tree[1]/field[@name='date_planned']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//field[@name='order_line']/tree[1]/field[@name='analytic_tag_ids']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//field[@name='origin']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
@ -252,7 +264,6 @@
<field name="recommendation_order" readonly="1" attrs="{
'invisible': [('purchase_commitee', '=', False)]}"/>
</field>
<xpath expr="//field[@name='origin']" position="replace">
<field name="send_to_budget" invisible="1"/>
<field name="email_to_vendor" invisible="1"/>
@ -263,7 +274,6 @@
<field name="is_signed" invisible="1"/>
</xpath>
<xpath expr="//field[@name='order_line']" position="attributes">
<attribute name="attrs">{'readonly':[('state','in',('done','cancel','waiting'))]}</attribute>
</xpath>
@ -273,7 +283,6 @@
<xpath expr="//field[@name='date_order']" position="attributes">
<attribute name="attrs">{'readonly':[('state','in',('done','cancel','waiting'))]}</attribute>
</xpath>
<xpath expr="//field[@name='currency_id']" position="after">
<field name="state_of_delivery"/>
<field name="is_purchase_budget" invisible="1"/>
@ -293,7 +302,6 @@
<xpath expr="//form//notebook//page//field//tree" position="attributes">
<attribute name="delete">true</attribute>
</xpath>
<xpath expr="//field[@name='price_subtotal']" position="after">
<field name="department_name"
attrs="{'readonly':[('parent.state','in',('done','cancel','waiting', 'sign'))]}"/>
@ -303,7 +311,8 @@
</xpath>
<!-- i edit here readonly="1"-->
<xpath expr="//notebook//page[1]" position="after">
<page string="Committe Members" groups="purchase_requisition_custom.committe_member" attrs="{'invisible':[('requisition_id','=', False)]}">
<page string="Committe Members" groups="purchase_requisition_custom.committe_member"
attrs="{'invisible':[('requisition_id','=', False)]}">
<field name="committe_members">
<tree>
<field name="user_id"/>
@ -315,41 +324,6 @@
</field>
</page>
</xpath>
<xpath expr="//button[@name='button_confirm']" position="attributes">
<attribute name="groups">purchase.group_purchase_manager</attribute>
<attribute name="states">draft</attribute>
<attribute name="attrs">
{'invisible':[('state', '=', 'draft'),
('is_purchase_budget', '=', True)]}
</attribute>
{"invisible": [["state", "=", "draft"], ["is_purchase_budget", "=", true]]}
</xpath>
<xpath expr="//button[@name='button_confirm'][1]" position="attributes">
<attribute name="groups">purchase.group_purchase_manager</attribute>
<attribute name="states">sent</attribute>
<attribute name="attrs">
{'invisible':[('state', '=', 'sent'),
('is_purchase_budget', '=', True)]}
</attribute>
</xpath>
<xpath expr="/form/header/button[@name='action_rfq_send']" position="attributes">
<attribute name="groups">purchase.group_purchase_manager, purchase.group_purchase_user</attribute>
</xpath>
<xpath expr="/form/header/button[@name='action_rfq_send'][1]" position="attributes">
<attribute name="states">wait,draft,wait_for_send</attribute>
<attribute name="groups">purchase.group_purchase_manager, purchase.group_purchase_user</attribute>
</xpath>
<xpath expr="/form/header/button[@name='action_rfq_send'][2]" position="attributes">
<attribute name="groups">purchase.group_purchase_manager, purchase.group_purchase_user</attribute>
</xpath>
<!-- Update each print_quotation button -->
<xpath expr="/form/header/button[@name='print_quotation']" position="attributes">
<attribute name="groups">purchase.group_purchase_manager, purchase.group_purchase_user</attribute>
<attribute name="states">draft,wait,wait_for_send</attribute>
</xpath>
</field>
</record>
<!-- Inherit the Purchase Requisition form and adding buttons to header tag -->
@ -362,24 +336,25 @@
<xpath expr="//form" position="attributes">
<attribute name="delete">0</attribute>
</xpath>
<xpath expr="//div[@name='button_box']" position="inside">
<xpath expr="//div[@name='button_box']" position="inside">
<button name="get_attachments" type="object"
class="oe_stat_button"
icon="fa-file-text-o">
<field name="attach_no" widget="statinfo" string="Documents"/>
</button>
</xpath>
</xpath>
<xpath expr="//div[@name='button_box']//button[@name='%(purchase_requisition.action_purchase_requisition_list)d']" position="replace">
<xpath expr="//div[@name='button_box']//button[@name='%(purchase_requisition.action_purchase_requisition_list)d']"
position="replace">
<button name="action_purchase_orders_view" type="object" class="oe_stat_button" icon="fa-list-alt"
attrs="{'invisible': [('state', '=', 'draft')]}">
attrs="{'invisible': [('state', '=', 'draft')]}">
<field name="order_count" widget="statinfo" string="RFQs/Orders"/>
</button>
</xpath>
<xpath expr="//field[@name='name']" position="after">
</xpath>
<xpath expr="//field[@name='name']" position="after">
<field invisible="1" readonly="1" name='res_model'/>
<field invisible="1" readonly="1" name='res_id'/>
</xpath>
</xpath>
<!-- header modificaton -->
<xpath expr="/form/header/button[@name='action_open']" position="after">
<button type="object" groups="purchase_requisition_custom.group_accept_purchase_requisition"
@ -466,7 +441,8 @@
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="/form/header/field[@name='state']" position="replace">
<field name="state" widget="statusbar" statusbar_visible="draft,in_progress,done" attrs="{'invisible': [('is_quantity_copy', '=', 'none')]}"/>
<field name="state" widget="statusbar" statusbar_visible="draft,in_progress,done"
attrs="{'invisible': [('is_quantity_copy', '=', 'none')]}"/>
</xpath>
<xpath expr="//field[@name='date_end']" position="before">
<!-- <field name="agreement_name" attrs="{'readonly': [('state','!=', 'draft')]}"/>-->
@ -500,7 +476,8 @@
<attribute name="attrs">{
'readonly': [('state','in',('cancel','checked','done','waiting'))],
'required': [('type_exclusive', '=', 'multiple')]
}</attribute>
}
</attribute>
</xpath>
<xpath expr="//field[@name='ordering_date']" position="attributes">
<attribute name="required">1</attribute>
@ -512,7 +489,10 @@
</xpath>
<xpath expr="//notebook/page[1]/field[@name='line_ids']/tree[1]/field[@name='account_analytic_id']"
position="replace">
<field name="account_analytic_id" attrs="{'column_invisible':[('parent.is_purchase_budget','=',False)]}" domain="['|', ('company_id', '=', False), ('company_id', '=', parent.company_id)]" groups="analytic.group_analytic_accounting"/>
<field name="account_analytic_id"
attrs="{'column_invisible':[('parent.is_purchase_budget','=',False)]}"
domain="['|', ('company_id', '=', False), ('company_id', '=', parent.company_id)]"
groups="analytic.group_analytic_accounting"/>
</xpath>
<xpath expr="//notebook/page[1]/field[@name='line_ids']/tree[1]/field[@name='account_analytic_id']"
position="after">