Author: ananthukrishna

How to change a context or domain value from base code – odoo


    <record id="hr.open_view_employee_list_my" model="ir.actions.act_window">
        <field name="context">{'default_employee_type':'permanent'}</field>
    </record>
Advertisements

post follower message – odoo


body = "Follower Message!"

records = self._get_followers(cr, uid, ids, None, None, context=context)
followers = records[ids[0]]['message_follower_ids']
self.message_post(cr, uid, ids, body=body, subtype='mt_comment', partner_ids=followers, context=context)

merge same product id one2many odoo (group by dictionary python) – odoo


input = [
{'product_id': '001', 'location_id': 'NISR', 'qty': 100, 'uom_id': 'roll', 'cost' :50, 'categ_id': 'ALL'},
{'product_id': '001', 'location_id': 'NISR', 'qty': 200, 'uom_id': 'roll', 'cost' :50, 'categ_id': 'ALL'},
{'product_id': '001', 'location_id': 'NISR', 'qty': 300, 'uom_id': 'roll', 'cost' :50, 'categ_id': 'ALL'},
{'product_id': '002', 'location_id': 'NISR', 'qty': 400, 'uom_id': 'roll', 'cost' :20, 'categ_id': 'ALL/SUB'},
{'product_id': '002', 'location_id': 'NISR', 'qty': 500, 'uom_id': 'roll', 'cost' :20, 'categ_id': 'ALL/SUB'},
{'product_id': '002', 'location_id': 'NISR', 'qty': 600, 'uom_id': 'roll', 'cost' :20, 'categ_id': 'ALL/SUB'},
{'product_id': '003', 'location_id': 'NISR', 'qty': 700, 'uom_id': 'roll', 'cost' :30, 'categ_id': 'ALL'},
]

grouper = itemgetter("product_id", "location_id", "uom_id" ,"cost")
result = []
for key, grp in groupby(sorted(input, key = grouper), grouper):
    temp_dict = dict(zip(["product_id", "location_id","uom_id", "cost"], key))
    temp_dict["categ_id"]=  (list(set(item["categ_id"] for item in grp))[0])
    temp_dict["qty"] = sum(item["qty"] for item in grp)
    temp_dict["amount"] =  temp_dict["cost"] * temp_dict["qty"]
    result.append(temp_dict)
    
from pprint import pprint
pprint(result)

output
[{'amount': 0,
  'categ_id': 'ALL',
  'cost': 50,
  'location_id': 'NISR',
  'product_id': '001',
  'qty': 0,
  'uom_id': 'roll'},
 {'amount': 0,
  'categ_id': 'ALL/SUB',
  'cost': 20,
  'location_id': 'NISR',
  'product_id': '002',
  'qty': 0,
  'uom_id': 'roll'},
 {'amount': 0,
  'categ_id': 'ALL',
  'cost': 30,
  'location_id': 'NISR',
  'product_id': '003',
  'qty': 0,
  'uom_id': 'roll'}]

mail create using python – odoo


@api.model
    def create(self, vals):
        values = {}
        mail_mail = self.env['mail.mail']
       
        # context: no_log, because subtype already handle this
        result = super(HelpdeskTicket, self.with_context(mail_create_nolog=True)).create(vals)

        values['subject'] = 'ePillars Support Case Created - %s  [%s]' % (result.name,result.id)
        values['body_html'] = """<html>
                                <head></head>
                                <body>    
                                Case Number:	"""+str(result.id) +"""<br/>
                                Support Account Name:	"""+ str(result.partner_id.name)+"""<br/>
                                Support Account Email:	"""+ str(result.partner_email)+"""<br/>
                                Status:	New <br/>
                                Subject:	"""+str(result.name) +"""<br/><br/><br/>


                                You will not be able to 'Reply' to this e-mail. If you wish to contact us,<br/> 
                                Please call +97143263939.
                                </body>
                                </html>
                                """
        values['email_from'] = 'ePillars Support<support@epillars.com>'
        values['email_to'] = result.partner_email
        values['reply_to'] = 'noreply<noreply@epillars.com>'
        if values['email_to']:
            mail= mail_mail.create(values)
        return result

Reinstall mysql server using Ubuntu Terminal


To remove or uninstall Mysql Client Core 5.5 separately, I used the following commands:

sudo apt-get remove –purge mysql-server mysql-client mysql-common
sudo apt-get remove –purge mysql-client-core-5.5
sudo apt-get autoremove
sudo apt-get autoclean
sudo rm -rf /var/lib/mysql

Now install or reinstall mysql client and server:

sudo apt-get install mysql-server
sudo apt-get install mysql-client
sudo apt-get install mysql-workbench

How to add new button box – odoo


class Employee(models.Model):
    _inherit = "hr.employee"


    @api.multi
    def view_onboard(self):
        onboard_ids = []
        action = self.env.ref('feag_hr.open_view_onboarding_action').read()[0]

        onboard = self.env['employee.onboard'].search([('name', '=', self.id)])
        for data in onboard:
            onboard_ids.append(data.id)

        action['domain'] = [('id', 'in', onboard_ids)]
        return action
<record id="cf_hr_onboard_view_employee_form" model="ir.ui.view">
        <field name="name">hr.employee.form</field>
        <field name="model">hr.employee</field>
        <field name="inherit_id" ref="hr.view_employee_form"/>
        <field name="arch" type="xml">
            <xpath expr="//div[@name='button_box']" position="inside">
                <button name="view_onboard" type="object" string="Onboarding" groups="hr.group_hr_user"
                                    class="oe_stat_button" icon="fa-file-text">
                </button>
            </xpath>
        </field>
    </record>