attrs="{'invisible': [('rule_id.type_test', '!=', 'A')]}" in code above not work, how i can fix this?
class test_list(models.Model):
_name = 'test.list'
type_test = fields.Selection([('A', 'aaaa'),('B','bbbbb')], default='A', string="Type", required=True)
rule_list = fields.One2many('test.rule', 'rule_id')
class test_rule(models.Model):
_name = 'test.rule'
rule_id = fields.Many2one('test.list', required=True)
ul = fields.Many2one('product.ul', string='Package Logistic Unit'
<record model="ir.ui.view" id="rules_form_view">
<field name="name">test.rules.form.view</field>
<field name="model">test.rule</field>
<field name="arch" type="xml">
<form string="Test Rules">
<field name="ul" attrs="{'invisible': [('rule_id.type_test', '!=', 'A')]}"/>
</form>
</field>
</record>
The fields you use in attrs need to be present in the current view.
You can add this field to model:
class test_rule(models.Model):
_name = 'test.rule'
rule_id = fields.Many2one('test.list', required=True)
type_test = fields.Selection(related='rule_id.type_test')
ul = fields.Many2one('product.ul', string='Package Logistic Unit')
And then to your form:
<form string="Test Rules">
<field name="type_test" invisible="1"/>
<field name="ul" attrs="{'invisible': [('type_test', '!=', 'A')]}"/>
</form>
Related
i suppose I've not fully undrestood the prototype inheritance in Odoo.
I try to inherit crm.lead
The Model :
` class learn_odoo(models.Model):
_name = 'learn_odoo.learn_odoo'
_inherit = ['crm.lead']
_description = 'learn_odoo.learn_odoo'
tag_ids = fields.Many2many('mail.channel','mail_channel_profile_crm', 'partner_id', 'tag_id')
job = fields.Char()`
The View :
`<record id="view_inherit_list_crm" model="ir.ui.view">
<field name="name">Learn Odoo</field>
<field name="model">learn_odoo.learn_odoo</field>
<field eval="1" name="priority"/>
<field name="inherit_id" ref="crm.crm_case_tree_view_oppor"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='name']" position="after">
<field name="job"/>
</xpath>
</field>
</record>
<record id="learn_odoo.action_window" model="ir.actions.act_window">
<field name="name">Learn Odoo</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">learn_odoo.learn_odoo</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
</p>
<p>
</p>
</field>
</record>`
The problem I encountered :
From your question, what i understood is you are trying to inherit crm.lead if i am right then please remove the _name = 'learn_odoo.learn_odoo'
you have to do as i am doing below:
class learn_odoo(models.Model):
_inherit = 'crm.lead'
tag_ids = fields.Many2many('mail.channel','mail_channel_profile_crm', 'partner_id', 'tag_id', string='Tag')
job = fields.Char('Job')
also in __manifest__.py file add crm in depends.
If you are not clear about inheritance please go through the odoo docs for inheritance from this Link for inheritance select your odoo version from top right corner for better results.
Odoo generates form with default "Odoo" title. I want to write my own title, how to do that?
here is also .xml fo this form:
<record model="ir.ui.view" id="email_compose_message_wizard_form">
<field name="name">mail.compose.message.form</field>
<field name="model">mail.compose.message</field>
<field name="groups_id" eval="[Command.link(ref('base.group_user'))]"/>
<field name="arch" type="xml">
<form string="Compose Email">
<div style="display_none">
<group>
<!-- truly invisible fields for control and options -->
<field name="composition_mode" invisible="1"/>
<field name="model" invisible="1"/>
<field name="res_id" invisible="1"/>
<field name="is_log" invisible="1"/>
<field name="parent_id" invisible="1"/>
...
and .py model:
class MailComposer(models.TransientModel):
_name = 'mail.compose.message'
_inherit = 'mail.composer.mixin'
_description = 'Email composition wizard'
_log_access = True
_batch_size = 500
When the action name is set, Odoo will use it as a title for the dialog
if (action.target === "new") {
cleanDomFromBootstrap();
const actionDialogProps = {
// TODO add size
ActionComponent: ControllerComponent,
actionProps: controller.props,
};
if (action.name) {
actionDialogProps.title = action.name;
}
Odoo will try to use the action name first then the default title (Odoo)
In task templates form i can add group_id. I want to make a domain that will add task templates depending in what group they belong but kinda have no clue now.
class ProjectTaskGroup(models.Model):
_name = 'project.task.group'
_inherit = 'project.object'
name = fields.Char(string="Name", required=True)
class ProjectTaskTemplate(models.Model):
_name = 'project.task.template'
_inherit = 'project.object'
name = fields.Char(string="Name", required=True)
group_id = fields.Many2one('project.task.group', string="Task Group")
<!-- Project Task Views -->
<record id="view_task_form2" model="ir.ui.view">
<field name="name">project.task.form</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_form2"/>
<field name="arch" type="xml">
<xpath expr="//div[#class='oe_title']" position="before">
<div class="oe_inline oe_edit_only">
<field name="group_id" class="oe_inline"/>
<field name="task_template_id" class="oe_inline"/>
</div>
</xpath>
</field>
</record>
First add field in model 'project.task.group'
template_id = fields.One2many('project.task.template', 'group_id', string='Group task')
Field of 'project.task'
task_template_id = field.Many2one('project.task.template')
group_id=field.Many2one('project.task.group')
In view of 'project.task'
<field name="task_template_id" class="oe_inline"/>
<field name="group_id" class="oe_inline" domain="[('template_id', '=', task_template_id)]"/>
first select template so we get group_id belogs to task_template_id
In Product form view there is Button Sale. When you activate it shows tree view with all sale orders for this product. My goal is to make the same button but it has to show all pos orders that was made with this product.
i tried something like this but i know it's total garbage. If someone could explain to me how it works i will be more then grateful
<record id="act_product_pos_sale" model="ir.actions.act_window">
<field name="name">POS Product Sale1</field>
<field name="res_model">product.product</field>
<field name="view_id" ref="product.product_product_tree_view"/>
</record>
<record model="ir.ui.view" id="product_form_pos_sale_button">
<field name="name">product.product.sale.pos.order</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view"/>
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button class="oe_stat_button" name="action_view_pos_product"
type="object" icon="fa-usd">
<field string="POS" name="pos_product_order_total" widget="statinfo" />
</button>
</div>
</field>
</record>
class ProductProduct(models.Model):
_inherit = 'product.product'
#api.multi
def action_view_pos_product(self):
OrderLine = self.env['pos.order.line']
action = self.env.ref('sale.act_product_pos_sale')
# action['domain'] = [('product_id', 'in', products.ids)]
# action['context'] = {'': ,}
return action
You add action and call that action using button:
Step 1: you have to calculate total pos sale count using compute method:
class ProductProduct(models.Model):
_inherit = 'product.product'
#api.multi
def _pos_sales_count(self):
r = {}
domain = [
('state', 'in', ['sale', 'done']),
('product_id', 'in', self.ids),
]
for group in self.env['report.pos.order'].read_group(domain, ['product_id', 'product_qty'], ['product_id']):
r[group['product_id'][0]] = group['product_qty']
for product in self:
product.sales_count = r.get(product.id, 0)
return r
pos_sales_count = fields.Integer(compute='_pos_sales_count', string='#Pos Sales')
class ProductTemplate(models.Model):
_inherit = 'product.template'
#api.multi
#api.depends('product_variant_ids.pos_sales_count')
def _pos_sales_count(self):
for product in self:
product.pos_sales_count = sum([p.sales_count for p in product.product_variant_ids])
pos_sales_count = fields.Integer(compute='_pos_sales_count', string='#POS Sales')
Step 2 : define action to link pos order line related to product:
<record id="action_product_pos_sale_list" model="ir.actions.act_window">
<field name="name">Sale Order Lines</field>
<field name="res_model">pos.order.line</field>
<field name="context">{'search_default_product_id': [active_id], 'default_product_id': active_id}</field>
</record>
<record model="ir.ui.view" id="product_form_view_pos_sale_order_button">
<field name="name">product.product.pos.sale.order</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view"/>
<field name="groups_id" eval="[(4, ref('sales_team.group_sale_salesman'))]"/>
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button class="oe_stat_button" name="%(action_product_pos_sale_list)d"
type="action" icon="fa-usd">
<field string="Sales" name="pos_sales_count" widget="statinfo" />
</button>
</div>
</field>
</record>
I have a custom module with the following simple data structure:
class Site(models.Model):
_name = 'sites.site'
site_name = fields.Char(string="Site Name")
contact_in_site_role_ids = fields.One2many(comodel_name="sites.contact_in_site_role", inverse_name="site_id", string="Site Contacts", required=False, )
class SiteRole(models.Model):
_name = "sites.site_role"
role_name = fields.Char(string="Role Name")
class ContactInSiteRole(models.Model):
_name = "sites.contact_in_site_role"
site_id = fields.Many2one("sites.site",string="Site")
contact_id = fields.Many2one("res.partner",string="Contact")
role_id = fields.Many2one("sites.site_role",string="Site Role")
role_detail = fields.Char(string="Role details")
This is currently managed by the following form:
<record model="ir.ui.view" id="site_form_view">
<field name="name">site.form</field>
<field name="model">sites.site</field>
<field name="arch" type="xml">
<form string="Site Form">
<sheet>
<group>
<field name="site_name"/>
</group>
<notebook>
<page string="Site Contacts">
<field name="contact_in_site_role_ids" widget="one2many_list">
<tree>
<field name="contact_id"/>
<field name="role_id"/>
<field name="role_detail"/>
</tree>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
This works well, apart from when clicking to add a contact on the Many2One widget on the "Edit Site Form", it prompts again for the site. How do I remove the "Site" option from this popup form, and have the relevant site passed from the parent form:
Try to pass like below and see
<field name="contact_in_site_role_ids" widget="one2many_list" context="{'default_site_id':parent.id}"/>
The concept here is we can initialize the child element values by passing them in the context like:
{default_child_field: value}