What is the problem in domain in Server Actions - odoo

I used ir.actions.server model for add an option in action menu item.
Main purpose for using this is to run python code from here.Here i don't want to return a tree or form view here , so i used this method.
I need to add an option only in vendor bills form, but the option is set both invoice and supplier form.
<record id="account_invoice_accrual_entries_vendor_bill_non_po_action" model="ir.actions.server">
<field name="name">Accrual Entries</field>
<field name="model_id" ref="model_account_invoice"/>
<field name="domain">[('type','in',('in_invoice'))]</field>
<field name="state">code</field>
<field name="code">
if records:
records.action_accrual_entries_vendor_bill()
</field>
</record>
<record id="account_invoice_accrual_entries_vendor_bill_non_po" model="ir.values">
<field name="model_id" ref="account.model_account_invoice"/>
<field name="name">Accrual Entries</field>
<field name="key2">client_action_multi</field>
<field name="key">action</field>
<field name="model">account.invoice</field>
<field name="value" eval="'ir.actions.server,' + str(ref('account_invoice_accrual_entries_vendor_bill_non_po_action'))" />
</record>
This is the code i try to add domain only for vendor bills. But the option visible in both vendor bills and customer invoice.
anyone knows what is the mistake in my code .??

Related

Odoo 15 Helpdesk formatting ID field

I need help with the modul Helpdesk. I wanted to add the field ID into the tree view via Addon. I could manage to do so, but now I want to format the field like this Ticket ID : #1234, at the moment its in this kind of format : Ticket ID 1,234. I also canĀ“t find the field ID in the source code.
This my code for the tree view:
<!-- Helpdesk Addon Tree View -->
<record id="helpdesk_addon_tree_view" model="ir.ui.view">
<field name="name">view.helpdesk.addon.tree</field>
<field name="model">helpdesk.ticket</field>
<field name="inherit_id" ref="helpdesk.helpdesk_tickets_view_tree"/>
<field name="arch" type="xml">
<field name="display_name" position="before">
<field name="id" string="ID"/>
</field>
<field name="stage_id" position="after">
<field name="create_date"/>
</field>
</field>
</record>
</odoo>
The id is a number and you can't format it, as a workaround you can add new Char field and override create method to fill it then you can use the new created field in the list view.
from odoo import models, api, fields, _
class HelpdeskTicket(models.Model):
_inherit = 'helpdesk.ticket'
ticket_no = fields.Char(string="Ticket No")
#api.model_create_multi
def create(self, list_value):
tickets = super(HelpdeskTicket, self).create(list_value)
# set ticket Id
for ticket in tickets:
if ticket.id:
ticket.ticket_no= '#' + str(ticket.id)
return tickets
XML will be:
<!-- Helpdesk Addon Tree View -->
<record id="helpdesk_addon_tree_view" model="ir.ui.view">
<field name="name">view.helpdesk.addon.tree</field>
<field name="model">helpdesk.ticket</field>
<field name="inherit_id" ref="helpdesk.helpdesk_tickets_view_tree"/>
<field name="arch" type="xml">
<field name="display_name" position="before">
<field name="ticket_no" string="ID"/>
</field>
<field name="stage_id" position="after">
<field name="create_date"/>
</field>
</field>
</record>
</odoo>

How to make dropdown for groups instead of checkboxes in Odoo?

I have made some groups A,B,C,D through GUI in Odoo v10. These groups are shown as check-boxes on the user page.
I want that instead of these check-boxes a dropdown must be shown so that user can be assigned to only a single group i.e. a user can only be in one of the A,B,C,D groups.
How can i do this??
I've found something that will clear how drop-downs are made and how check boxes are made. This is through code not from GUI as i am still finding a solution for it.
So, drop-downs are made when each group in a category inherits some other group in same category in hierarchical manner.
So, when i wrote the following code, check-boxes were made.
<record id='group_category' model='ir.module.category'>
<field name='name'>Category name</field>
</record>
<record id="group_a" model="res.groups">
<field name="name">A</field>
<field name="category_id" ref="group_category"/>
</record>
<record id="group_b" model="res.groups">
<field name="name">B</field>
<field name="category_id" ref="group_category"/>
</record>
<record id="group_c" model="res.groups">
<field name="name">C</field>
<field name="category_id" ref="group_category"/>
</record>
But when i wrote the following code in which one group inherits the other in a hierarchical way, drop-down was made
<record id='group_category' model='ir.module.category'>
<field name='name'>Category name</field>
</record>
<record id="group_a" model="res.groups">
<field name="name">A</field>
<field name="category_id" ref="group_category"/>
</record>
<record id="group_b" model="res.groups">
<field name="name">B</field>
<field name="category_id" ref="group_category"/>
<field name="implied_ids" eval="[(4, ref('module_name.group_a'))]"/>
</record>
<record id="group_c" model="res.groups">
<field name="name">C</field>
<field name="category_id" ref="group_category"/>
<field name="implied_ids" eval="[(4, ref('module_name.group_b'))]"/>
</record>
so, this was the case when i did it. Still finding a way to do it through GUI.
First Create this below record through xml.
<record model="ir.module.category" id="abcd_category">
<field name="name">ABCD</field>
</record>
Then Create your groups with category_id.
<record id="group_a" model="res.groups">
<field name="name">A</field>
<field name="category_id" ref="abcd_category"/>
</record>
<record id="group_b" model="res.groups">
<field name="name">B</field>
<field name="category_id" ref="abcd_category"/>
</record>
......
......
Thats it.
Updates :
Add category in manifest.py
....
....
'category':'ABCD',
....
....
and select it from view into the Application in group formview.
You can override the view and specify a widget. You could try:
<field name="field_name" widget="selection"/>
or
<field name="field_name" widget="many2one"/>
I hope this help you!

Odoo - How can I get some field's value in purchase module to show in stock module?

How can I get some field's value in purchase module to show in stock module?
I want to show field (po_name) in purchase module in tree view of stock module.
This is my code
<record id="vpicktree_kwan" model="ir.ui.view">
<field name="name">stock.picking.tree.kwan</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.vpicktree"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="po_name" string="PO number"/>
</field>
</field>
</record>
Could you guide me please?

How do I trigger code on order confirmation in Odoo?

I've setup a ir.server.action that reacts to when the model is saved and is in a manual state. However repeated saves will repeatedly trigger the action, so I have to lock on the database. Currently I have this:
<record id="filter_order_confirm" model="ir.filters">
<field name="name">By Confirmed Orders</field>
<field name="model_id">sale.order</field>
<field name="domain">[('state','=','manual')]</field>
</record>
<record id="action_schedule_emails" model="ir.actions.server">
<field name="state">code</field>
<field name="model_id" ref="sale.model_sale_order"/>
<field name="code">object.schedule_emails()</field>
<field name="type">ir.actions.server</field>
<field name="condition">True</field>
<field name="name">Schedule Emails</field>
</record>
<record id="rule_trigger_email_scheduling" model="base.action.rule">
<field name="name">Trigger email scheduling when Order is set to confirm.</field>
<field name="model_id" ref="sale.model_sale_order" />
<field name="kind">on_create_or_write</field>
<field name="filter_id" ref="filter_order_confirm" />
<field name="server_action_ids" eval="[(6,0,[ref('action_schedule_emails')])]" />
</record>
How can I react to the order being confirmed in the workflow instead?
You can modify the workflow activity to trigger any server action when is executed.
In your case you need to modify the act_router activity in sale.wkf_sale this can be done from your addon like this.
<record id="sale.act_router" model="workflow.activity">
<field name="action_id" ref="action_schedule_emails"/>
</record>
With this modification the code on your server action is triggered when the order is confirmed.

How to define the action that occurs when clicking a tree view row in OpenERP?

I haven't been able to figure out how to define what action occurs when clicking a row in an OpenERP tree view. I've created a custom tree view for showing product suppliers (product.supplierinfo). Ideally I would like to open the form view for the product.product object with the Suppliers tab active and not a view of the product.supplierinfo object (as it does now). Is this possible? At a minimum I would like to open a popup window containing a view of the supplierinfo with a link to the parent product.
The supplier info view (default_code, manuf_name and manuf_code are all custom fields added to the product.supplierinfo model):
<record id="product_suppliers_tree_view" model="ir.ui.view">
<field name="name">product.suppliers.tree.view</field>
<field name="model">product.supplierinfo</field>
<field name="type">tree</field>
<field name="priority">16</field>
<field name="arch" type="xml">
<tree string="Product Suppliers">
<field name="default_code"/>
<field name="product_id"/>
<field name="name"/>
<field name="product_code"/>
<field name="manuf_name"/>
<field name="manuf_code"/>
</tree>
</field>
</record>
Supplier info action:
<record id="product_suppliers_action" model="ir.actions.act_window">
<field name="name">Product Suppliers</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">product.supplierinfo</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="product_suppliers_tree_view"/>
<field name="help">Here you can search for products by supplier information, including supplier and manufacturer name and part number. Each product can have one or more supplier sources.</field>
</record>