Sunday, December 6, 2020

open specific view from many2one field

 ODOO 



In this case we have many2one field for model that has more than one view and we want to open specific view from this field for this model

let us give an example :

- we have model "object.a" and model "object.b", in which we have object_a_id field as bellow 

object_a_id = fields.Many2one('object.a', string="Object A")

 

- model "object.a" has two form view with ids "object_a_form_view_1" and "object_a_form_view_2" and "object_a_form_view_1" id the default view and we want to show the other view from object_a_id field , so we can do it by add the field in the xml file as bellow

 

<field name="object_a_id" context="{'form_view_ref':'module_name.object_a_form_view_2',}" />

Thursday, December 3, 2020

OperationalError: FATAL: the database system is starting up

ODOO



The error above happen when the postgres database service can not start , so to fix it we have to restart the postgres by opening the terminal and write the command bellow 

sudo service postgresql restart

Tuesday, December 1, 2020

The tag is deprecated, use a tag for

 ODOO 

odoo 14


 

"The <report> tag is deprecated, use a <record> tag for ...etc "

some time you can get the error above when you create new report tin odoo 14.0 because 90% created it as bellow ,

<report
            id="report_action_id"
            string="Report Name"
            model="model.name"
            report_type="qweb-html"
            name="module_name.report_temp_id"
            menu="True"
        />


But , You have to create it as bellow to fix this error 

 

<record id="report_action_id" model="ir.actions.report">
        <field name="name">Report Name</field>
        <field name="model">model.name</field>
        <field name="report_type">qweb-pdf</field>
        <field name="report_name">module_name.report_temp_id</field>
        <field name="report_file">module_name.report_temp_id</field>
        <field name="binding_model_id" ref="model.name"/>
        <field name="binding_type">report</field>

</record>

Friday, November 27, 2020

many2one field domain from function

 ODOO

 odoo 14


 

in this blog we will explain how we can define domain for Many2one field in odoo 14 , so let us start 

 

First we have "object.a" model which is contain Many2many in which we will add many users , as bellow

user_ids = fields.Many2many('res.users', string="Users")

Second we have "object.b" model , which we have user_id field that contain the current user , and object_a_id which is Many2one field from object "A" , as bellow

user_id = fields.Many2one('res.users', string='Created By', default=lambda self: self.env.user, readonly=True)

object_a_id = fields.Many2one('object.a', string="A")

and we need to make domain over object_a_id field to show only the records from object A that the current user is involved in the user_ids field 

....

To make the domain we have to add function as bellow  

    @api.onchange('some_field_in_B_object')
    def _get_object_b_ids(self):
        """
        function to get the A records for the current user
        """
        object_a_ids = self.env['object.a'].search([])
        ids_lis = []
        domain = [('id','=', -1)]

        for rec in object_a_ids:
            for line in rec.user_ids:
                if self.user_id == line:
                    ids_lis.append(rec.id)
        res = {}
        res['domain'] = {'object_a_id': [('id', 'in', ids_lis)]}
        return res



 

Wednesday, November 11, 2020

create new branch on github

GitHub

 

In the blog we will explain how we can create new branch on github from terminal , so follow the steps bellow 

 

1/ create new folder with name local_branch 

2/ open the terminal with it's path and write the comands bellow one by one

 

git init // to initialize local repo 

git add . // to add all folders in this folder to your local repo

git checkout -b local_branch // to make checkout 

git commit -m "any text message you want" // to commit your changes

git remote add origin remote_repo_path on github // to add your local branch to remote branch 

git push origin local_branch //  to push your files to the remote branch

Monday, November 2, 2020

random function in odoo 14

in this blog we will explain example to generate random number of 4 digits in odoo so let us start 

 

- First we have to import choice class from random package as bellow

from random import choice

- Then we have to import digits class from string package as bellow 

from string import digits

- Last we can use the function bellow that will return the random number

def _default_random_pin(self):
        return ("".join(choice(digits) for i in range(4)))

 

Wednesday, October 21, 2020

How to use many2one field in demo data

Odoo

Demo Data

 

 

 In this blog we will explain how to add value for many2one field in the xml demo data file in odoo , so let us start 

First let us say we have python object by the name 'report.create' which is contain the model_id field which is many2one field from 'ir.model' as bellow 

class ReportCreater(models.Model):
    _name = 'report.creater'

    model_id = fields.Many2one(
        'ir.model', string='Model', required=True, ondelete="cascade",
        help="The type of document this template can be used with")

and we want to create demo data for this object and the records from the demo data must contain the model_id field , so we can do it as bellow 

<odoo>
  <data noupdate="0">
    <record id="simple_contract_template" model="desined.report.template">
      <field model="ir.model" name="model_id" search="[('model', '=', 'res.partner')]"/>
    </record>
  </data>
</odoo>

 

*NOTES

  • 'ir.model' this object contain all models in the data base
  • search="[('model', '=', 'res.partner')] in this step we made search in the 'ir.model' object to return record from it , and in that record the value of model field must be 'res.partner'
  • 'ir.model' contain the model field which is char field

Odoo Invoice Qr code issues

There are two main issues must of us facing with the QR code in Odoo invoice & these issues are 1/ QR code displayed as broken image w...