Skip to content

Instantly share code, notes, and snippets.

View simahawk's full-sized avatar

Simone Orsi simahawk

View GitHub Profile
@simahawk
simahawk / test.py
Created June 13, 2016 14:56
odoo - stock picking package preparation -> get lot id for each line
picking_ids = line.package_preparation_id.picking_ids.ids
search_args = [
('picking_id', 'in', picking_ids),
('product_id', '=', line.product_id.id),
]
pack_items = self.env['stock.pack.operation'].search(search_args)
lots = []
for item in pack_items:
lots.extend([x.lot_id.name for x in item.pack_lot_ids])
@simahawk
simahawk / reflect.py
Created June 13, 2016 10:14 — forked from huyng/reflect.py
A simple echo server to inspect http web requests
#!/usr/bin/env python
# Reflects the requests from HTTP methods GET, POST, PUT, and DELETE
# Written by Nathan Hamiel (2010)
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from optparse import OptionParser
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
@simahawk
simahawk / various.py
Created June 10, 2016 11:09
odoo stuff
@api.model
def translate(self, term):
"""Load `term` translation."""
translations = self.env['ir.translation']
name = '' # can ben empty since we are passing the source = term
_type = 'code'
lang = self.env.context.get('lang')
return translations._get_source(name, _type, lang, source=term)
# -*- coding: utf-8 -*-
from copy import copy
from datetime import timedelta
ONE_DAY = timedelta(days=1)
class datetimerange(object):
"""Just like ``xrange``, but working on ``datetime``."""
@simahawk
simahawk / page.xml
Created March 10, 2016 16:32
Odoo website - qweb t-field display issue w/ empty field
<!--
here if you don't have a description you'll see "My description",
no matter if you can edit the page or not.
-->
<div t-field="main_object.description">My description</div>
<!--
my workaround ATM: render w/ `t-field` only if editable
-->
@simahawk
simahawk / assets.xml
Last active May 13, 2022 10:50
Override Odoo website builder text editor options
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template id="summernote" name="My summernote assets" inherit_id="web_editor.assets_editor">
<xpath expr="//script[last()]" position="after">
<script type="text/javascript" src="/my_mod/static/js/summernote_overrides.js"></script>
</xpath>
</template>
</odoo>
@simahawk
simahawk / configure.zcml
Created December 17, 2015 13:53
transforms to replace elements tag on the fly
<adapter
provides="plone.outputfilters.interfaces.IFilter"
name="b_to_strong"
for="* *"
factory=".transforms.BoldReplacer"
/>
<adapter
provides="plone.outputfilters.interfaces.IFilter"
name="i_to_em"
"""
Use with
bin/instance run export_skin_folder.py
This script will extract the portal_skins folder
named in SKINFODLER_NAME to the DEST directory
"""
import os
import sys
PLONE_PORTAL = 'Plone'
@simahawk
simahawk / main.js
Created July 27, 2015 07:59
Plone z3c.form datetime widget pure JS
(function ($) {
"use strict";
if ((typeof window.widgets) === 'undefined') {
window.widgets = {};
}
var widgets = window.widgets;
widgets.CalendarWidget = function (wrapper, settings) {
var self = this;
# custom_cookie_consent PT
<metal:macro define-macro="message">
<tal:block
define="ps context/@@plone_portal_state;
language ps/language;
root_url ps/navigation_root_url;
privacy_url_it string:${root_url}/it/privacy;
privacy_url_en string:${root_url}/en/privacy;"