Skip to content

Instantly share code, notes, and snippets.

View ray-odoo's full-sized avatar
💭
Spreading purple around the world!

Ray Carnes ray-odoo

💭
Spreading purple around the world!
View GitHub Profile
<?xml version="1.0"?>
<tree string="Forecasted Inventory" create="0" multi_edit="1" editable="top">
<field name="write_date"/>
<field name="write_uid"/>
<field name="origin" readonly="1"/>
<field name="picking_id" widget="one2many_button" readonly="1"/>
<field name="date"/>
<field name="x_step"/>
<field name="product_id" readonly="1"/>
<field name="product_packaging_id" optional="hide" groups="product.group_stock_packaging"/>
for record in records:
if record.model == 'project.task':
task = env['project.task'].search([('id','=',record.res_id)])
new_body = "<dl><dt>Project: </dt><dd>%s</dd>" % task.project_id.display_name
new_body += "<dt>Customer: </dt><dd>%s</dd>" % task.partner_id.display_name
new_body += "<dt>Deadline: </dt><dd>%s</dd>" % (task.date_deadline and task.date_deadline or 'N/A')
record['body_html'] = record.body_html + new_body + "</dl>"
https://www.odoo.com/documentation/14.0/reference/orm.html#fields
# simple Char field
name = fields.Char(string="Name", required="True", readonly="False", invisible="False", help="The name field help string", )
# note that required, readonly and invisible might be better defined in the View where they can be controlled via attrs
# to set a default
default='' # the name of the value
# Available variables:
# - env: Odoo Environment on which the action is triggered
# - model: Odoo Model of the record on which the action is triggered; is a void recordset
# - record: record on which the action is triggered; may be void
# - records: recordset of all records on which the action is triggered in multi-mode; may be void
# - time, datetime, dateutil, timezone: useful Python libraries
# - log: log(message, level='info'): logging function to record debug information in ir.logging table
# - UserError: Warning Exception to use with raise
# To return an action, assign: action = {...}
@ray-odoo
ray-odoo / action.code
Last active January 11, 2021 00:57
Leverage Employee Skills when assigning Tasks in the Projects App
# https://www.odoo.com/forum/help-1/how-can-i-leverage-employee-skills-when-assigning-tasks-in-the-projects-app-181599
###### Offboard:
env['ir.ui.view'].search([('name','=','custom_ray_odoo')]).unlink()
env['ir.model.fields'].search([('name','=','x_employee_skill_ids')]).unlink()
###### Onboard:
# Schema
for record in self:
if record.delivery_count > 0:
record['x_delivery_status'] = 'draft'
else:
global_done = False
for picking in record.picking_ids.sorted(key=lambda r: r.id):
local_done = False
if picking.state in ['waiting','confirmed']:
record['x_delivery_status'] = 'waiting'
if picking.state in ['assigned']:
# Available variables:
# - env: Odoo Environment on which the action is triggered
# - model: Odoo Model of the record on which the action is triggered; is a void recordset
# - record: record on which the action is triggered; may be void
# - records: recordset of all records on which the action is triggered in multi-mode; may be void
# - time, datetime, dateutil, timezone: useful Python libraries
# - log: log(message, level='info'): logging function to record debug information in ir.logging table
# - Warning: Warning Exception to use with raise
# To return an action, assign: action = {...}
# only tested with the speficic import file with the following schema:
# Internal ID,ID,Name,Asset Type,Asset Original Cost,Asset Current Cost,Serial Number,Quantity,Date Created,Purchase Date,Depreciation Start Date,Current Net Book Value,Cumulative Depreciation
import xlrd
import xmlrpc.client
import requests
import base64
import datetime
quants = env['stock.quant'].search([])
move_line_ids = []
warning = ''
for quant in quants:
move_lines = env["stock.move.line"].search([
('product_id', '=', quant.product_id.id),
('location_id', '=', quant.location_id.id),
('lot_id', '=', quant.lot_id.id),
('package_id', '=', quant.package_id.id),
<filter string="This Month" name="this_month" domain="['&amp;', ('date', '&gt;=', context_today().strftime('%Y-%m-01')),
('date', '&lt;', (context_today() + relativedelta(months=1)).strftime('%Y-%m-01'))]"/>
<filter string="Last Month" name="last_month1" domain="['&amp;', ('date', '&gt;=', (context_today() - relativedelta(months=1)).strftime('%Y-%m-01')),
('date', '&lt;', (context_today() - relativedelta(months=0)).strftime('%Y-%m-01'))]"/>
<filter string="2 Months Ago" name="last_month2" domain="['&amp;', ('date', '&gt;=', (context_today() - relativedelta(months=2)).strftime('%Y-%m-01')),
('date', '&lt;', (context_today() - relativedelta(months=1)).strftime('%Y-%m-01'))]"/>
<filter string="3 Months Ago" name="last_month3" domain="['&amp;', ('date', '&gt;=', (context_today() - relativedelta(months=3)).strftime('%Y-%m-01')),