Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
3 Antworten
1003 Ansichten
 This is my model and form view, I want to inherit account_move_views.xml(accounting->customer->invoice form view) with these 3 buttons, But existing module buttons are there, i want to disable those existing buttons, and also new status 'waiting' status should be visible in draft, waiting and post status too, but except waiting status, these waiting status is not visible? i want to fix this too? how? how can i modify both files??

from odoo import models, fields, api, _
from odoo.exceptions import UserError


class AccountMove(models.Model):
_inherit = 'account.move'

state = fields.Selection(
selection=[
('draft', 'Draft'),
('waiting_approval', 'Waiting For Approval'),
('posted', 'Posted'),
('cancel', 'Cancelled'),
],
string='Status',
required=True,
readonly=True,
copy=False,
tracking=True,
default='draft',
)

def action_send_for_approval(self):
"""Send invoice for approval"""
for record in self:
if record.move_type not in ('out_invoice', 'out_refund'):
raise UserError(_("Only customer invoices can be sent for approval."))
if record.state != 'draft':
raise UserError(_("Only Draft Invoices can be sent for approval"))
record.state = 'waiting_approval'
return True

def action_approve_invoice(self):
"""Approve invoice and post it"""
# Check if user has permission to approve
if not self.env.user.has_group('account.group_account_manager'):
raise UserError(_('Only Accounting managers can Send this to approval Stage'))

for record in self:
if record.state != 'waiting_approval':
raise UserError(_('Only Invoices waiting for approval Can Be approved.'))

# Post the Invoice
# record.action_post()
record.state = 'posted'

if record.partner_id and record.partner_id.email:
record._send_approval_email()

return True

def _send_approval_email(self):
"""Send email notification to customer"""
template = self.env.ref('vkd_accounting_approval_process.email_template_invoice_approved',
raise_if_not_found=False)
if template:
template.send_mail(
self.id,
force_send=True,
email_layout_xmlid='mail.mail_notification_light'
)

def action_draft(self):
res = super().action_draft()
for record in self:
if record.state == 'waiting_approval':
record.state = 'draft'
return res

@api.model
def _get_mail_template(self):
return self.env.ref('vkd_accounting_approval_process.invoice_approval_email', raise_if_not_found=False),<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<!-- _inherit_approval-->
<record id="view_move_form" model="ir.ui.view">
<field name="name">account.move.form.inherit.vkd_accounting_approval_process</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">

<xpath expr="//form/header" position="inside">

<button name="action_send_for_approval" string="Send For Approval" type="object" class="btn-primary"
invisible="state != 'draft'"/>
<button name="action_approve_invoice" string="Approve Invoice" type="object" class="btn-success"
groups="account.group_account_manager" invisible="state != 'waiting_approval'"/>
<button name="action_draft" string="Send to Draft" type="object" class="btn-secondary"
invisible="state != 'waiting_approval'"/>
</xpath>
</field>
<!-- Add approval information in form -->
</record>
</odoo>
Avatar
Verwerfen
Beste Antwort

Hii,
Updated XML:
<?xml version="1.0" encoding="UTF-8"?>

<odoo>

    <record id="view_move_form_inherit_approval" model="ir.ui.view">

        <field name="name">account.move.form.inherit.vkd_accounting_approval_process</field>

        <field name="model">account.move</field>

        <field name="inherit_id" ref="account.view_move_form"/>

        <field name="arch" type="xml">


            <!-- Override the statusbar to include 'waiting_approval' -->

            <xpath expr="//field[@name='state']" position="attributes">

                <attribute name="widget">statusbar</attribute>

                <attribute name="statusbar_visible">draft,waiting_approval,posted</attribute>

                <attribute name="readonly">1</attribute>

            </xpath>


            <!-- Remove default buttons -->

            <xpath expr="//form/header/button[@name='action_post']" position="attributes">

                <attribute name="invisible">1</attribute>

            </xpath>

            <xpath expr="//form/header/button[@name='button_draft']" position="attributes">

                <attribute name="invisible">1</attribute>

            </xpath>

            <xpath expr="//form/header/button[@name='button_cancel']" position="attributes">

                <attribute name="invisible">1</attribute>

            </xpath>


            <!-- Add custom buttons -->

            <xpath expr="//form/header" position="inside">

                <button name="action_send_for_approval"

                        string="Send for Approval"

                        type="object"

                        class="btn-primary"

                        attrs="{'invisible': [('state', '!=', 'draft')]}"/>

               

                <button name="action_approve_invoice"

                        string="Approve Invoice"

                        type="object"

                        class="btn-success"

                        groups="account.group_account_manager"

                        attrs="{'invisible': [('state', '!=', 'waiting_approval')]}"/>

               

                <button name="action_draft"

                        string="Send to Draft"

                        type="object"

                        class="btn-secondary"

                        attrs="{'invisible': [('state', '!=', 'waiting_approval')]}"/>

            </xpath>


        </field>

    </record>

</odoo>

 i hope it is use full

Avatar
Verwerfen
Autor Beste Antwort
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<!-- _inherit_approval-->
<record id="view_move_form" model="ir.ui.view">
<field name="name">account.move.form.inherit.vkd_accounting_approval_process</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">
<xpath expr="//button[@name='action_post']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//form/header" position="inside">
<button name="action_send_for_approval" string="Send For Approval" type="object" class="btn-primary"
invisible="state != 'draft'"/>
<button name="action_approve_invoice" string="Approve Invoice" type="object" class="btn-success"
groups="account.group_account_manager" invisible="state != 'waiting_approval'"/>
<button name="action_draft" string="Send to Draft" type="object" class="btn-secondary"
invisible="state != 'waiting_approval'"/>
</xpath>
</field>
</record>

</odoo> Updated view, this part is also i have, please look at my code, Nothing happen, same issue( I am a beginner)
Avatar
Verwerfen

Try the following code.

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<!-- _inherit_approval-->
<record id="view_move_form" model="ir.ui.view">
<field name="name">account.move.form.inherit.vkd_accounting_approval_process</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">
<xpath expr="//button[@name='action_post']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//button[@name='action_post']" position="after">
<button name="action_send_for_approval" string="Send For Approval" type="object" class="btn-primary"
invisible="state != 'draft'"/>
<button name="action_approve_invoice" string="Approve Invoice" type="object" class="btn-success"
groups="account.group_account_manager" invisible="state != 'waiting_approval'"/>
<button name="action_draft" string="Send to Draft" type="object" class="btn-secondary"
invisible="state != 'waiting_approval'"/>
</xpath>
</field>
</record>
</odoo>

Please ensure that the path of the file is correctly added in the manifest file.

Beste Antwort

Hi,


1- To disable the existing button in 'account.move', try the following.

<record id="view_move_view_form" model="ir.ui.view">
<field name="name">account.move.view.form.inherit</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">
<xpath expr="//button[@name='button_name']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
</field>
</record>


2- To add 'waiting' state.

class AccountMove(models.Model):
"""The model account move is inherited for adding new state"""
_inherit = 'account.move'

state = fields.Selection(
selection_add=[
('draft', 'Draft'),
('waiting', 'Waiting'),
('posted', 'Posted')
],
default='draft',
)

Upgrade the module after making the changes.


Hope it helps

Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
2
Aug. 25
1295
1
März 25
1477
1
Juni 25
675
0
Juni 25
126
1
Juni 25
563