Skip to content

Instantly share code, notes, and snippets.

View 3mrdev's full-sized avatar
👨‍💻
Messing things up

Amr Abd-Alkrim 3mrdev

👨‍💻
Messing things up
View GitHub Profile
@3mrdev
3mrdev / salary_rule.py
Last active October 14, 2024 13:30
Date filters one2many field in Payroll salary rules
# Access employee shipments and filter by payslip date range
shipment_count = len(employee.shipments.filtered(
lambda s: s.scheduled_date and s.scheduled_date.date() >= payslip.date_start and s.scheduled_date.date() <= payslip.date_end
))
# Return the shipment count for further calculations if needed
result = shipment_count
# Access employee shipments and filter by payslip date range
total_trip_cost = sum(employee.x_studio_one2many_field_5kk_1ia59qec4.filtered(
[options]
#
# WARNING:
# If you use the Odoo Database utility to change the master password be aware
# that the formatting of this file WILL be LOST! A copy of this file named
# /etc/odoo/openerp-server.conf.template has been made in case this happens
# Note that the copy does not have any first boot changes
#-----------------------------------------------------------------------------
# Odoo Server Config File - TurnKey Linux
@3mrdev
3mrdev / partner_orders_smart_button.py
Last active December 20, 2022 10:31
Using Inheritance Add a smart button with an action to view a list of one2many or many2many records
class Customer(models.Model):
_inherit = "res.partner"
orders = fields.One2many('sale.order', 'partner_id', string="Orders")
orders_count = fields.Integer(compute='_orders_count', string="Orders Count",store=True)
@api.depends("orders")
def _orders_count(self):
for rel in self:
count_id = self.env['sale.order'].search_count([('partner_id', '=', rel.id)])
@3mrdev
3mrdev / add_fields_signup.xml
Last active October 1, 2023 08:05
How to add more fields to the sign up page in Odoo?
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<!-- Inherit Form View to Modify it -->
<record id="kod_res_partner_inherit" model="ir.ui.view">
<field name="name">kod.res.partner.form.inherit</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
@3mrdev
3mrdev / custom_report.xml
Created October 8, 2022 17:04
How to make a custom report with a wizard in Odoo ?
<odoo>
<record model="report.paperformat" id="paperformat_a4">
<field name="name">paperformat.custom.report</field>
<field name="default" eval="True"/>
<field name="format">A4</field>
<field name="page_width">0</field>
<field name="page_width">0</field>
<field name="orientation">Portrait</field>
<field name="margin_top">30</field>
<field name="margin_right">5</field>
@3mrdev
3mrdev / __manifest__.py
Created October 8, 2022 16:46
How to add css and js to Odoo? (Odoo 15 and later)
{
'name':'Your module manifest name'
'assets': {
'web.assets_backend': [
'your_module/static/src/js/your_css.your_css',
'your_module/static/src/js/your_js.js',
],
'web.assets_common': [
'your_module/static/src/js/your_css.your_css',
'your_module/static/src/js/your_js.js',
@3mrdev
3mrdev / assets.xml
Created October 8, 2022 16:41
How to add css and js files to Odoo ? (Odoo 14 and previous versions)
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="assets_backend" name="doc assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/your_module/static/src/css/your_css.css"/>
<script type="text/javascript" src="/your_module/static/src/js/your_js.js"/>
</xpath>
</template>
</data>
@3mrdev
3mrdev / cron.xml
Created October 8, 2022 16:37
How to make a cron job in Odoo? (Recurrent Background Service)
<odoo>
<data noupdate="0">
<record id="cron_id" forcecreate='True' model="ir.cron">
<field name="name">Cron Name</field>
<field eval="True" name="active"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">5</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field name="model_id" ref="model_your_model_name"/>
@3mrdev
3mrdev / sequence.py
Created October 8, 2022 16:25
How to make odoo sequence ?
class your_model_class_name (models.Model):
_name = "your_model_name"
@api.model
def create(self, vals):
if vals.get('seq', 'New') == 'New':
vals['seq'] = self.env['ir.sequence'].next_by_code('example.seq') or '/'
newId = super(your_model_class_name, self).create(vals)
return newId
@3mrdev
3mrdev / account_move.py
Created October 8, 2022 13:43
How to create an invoice from any model in Odoo
def create_invoice(self):
move_dict = {
'narration': "Name",
'ref': name,
'journal_id': journal_id.id,
'date': date,
}
line_ids = []