Aug 14, 2019

odoo add followers when task change followers


just a simple automation




partners_who_are_users = []
users = env['res.users'].search([])
for user in users:
  partners_who_are_users.append(user.partner_id.id)

followers = []
for partner in record.project_id.message_follower_ids.ids:
  if partner in partners_who_are_users:
    followers.append(partner)



followers.append(record.user_id.partner_id.id)
record.project_id.message_subscribe(followers)


Read more ...

SOLVED odoo 11 Domains no longer working with dynamic dates

regarding to :
https://github.com/odoo/odoo/issues/22956

on V10, we can use :

[["create_date","<",time.strftime('%Y-%m-%d')]]  


this is a simple solution,

update base_automation set filter_pre_domain='[["write_date","<=", datetime.datetime.now().replace(microsecond=0).replace(hour=0).replace(minute=0).replace(second=0).isoformat(" ").partition("+")[0]  ]]', filter_domain='[["write_date","<=", datetime.datetime.now().replace(microsecond=0).replace(hour=0).replace(minute=0).replace(second=0).isoformat(" ").partition("+")[0]  ]]' where id=5;

main idea is change "%" notation from strftime to native, make it pass the "eval" to be compiled.



Read more ...

Aug 9, 2019

all about followers odoo

just as your inspiration only.

Automatically add follower to Sales Order if user(s) is a follower of the Contact - Odoo 10

10/18/18, 3:53 AM 1,075 views
How do I automatically add all followers from the partner to any new Sales Order with the same Partner?

So when a sales order is placed it will add all users following the Partner of the Sales Order to the Sales Order.



2
Ray Carnes United States
 10/18/18, 9:56 AM
An Automated Action (this example should work with v11 and v12) can combine the followers (this example adds ONLY followers who are Users) on the Sale Order and followers from the Customer:

Code to copy/paste:

partners_who_are_users = []
users = env['res.users'].search([])
for user in users:
  partners_who_are_users.append(user.partner_id.id)

followers = []
for partner in record.partner_id.message_partner_ids.ids:
  if partner in partners_who_are_users:
    followers.append(partner)
record.message_subscribe(followers)

=========================  

add followers automatically

12/18/13, 5:27 AM 10,045 views
Hello in crm.lead the responsible user (user_id) is automatically added as follower to the new task. How can I add this functionality to add some users to my custom object?



3
Ray Carnes United States
 2/9/18, 3:16 AM
To expand on David's answer, I needed to add the Customer as a follower on a LEAD in v10.
I created an Automated Action that looked for crm.lead records created or updated that also had either a Customer or Email populated.
If the record had a Customer, I needed to just add that Customer as a follower (as long as it wasn't already).
If the record had an Email, I needed to check if a Customer already existed, and if not - create them.
This is the code I used for the Server Action:
if record.partner_id: 
    partner = record.partner_id  
else: 
    partner = env['res.partner'].search([('email','=',record.email_from)]) 
if not partner: 
    reg = { 
           'name': record.contact_name or record.email_from, 
           'email': record.email_from, 
           'type': 'contact', 
          } 
    partner = env['res.partner'].create(reg) 
partner_id = partner.id 
reg = { 
       'res_id': record.id, 
       'res_model': 'crm.lead', 
       'partner_id': partner_id, 
      } 
if not env['mail.followers'].search([('res_id','=',record.id),('res_model','=','crm.lead'),('partner_id','=',partner_id)]): 
    follower_id = env['mail.followers'].create(reg)
Read more ...

Jul 12, 2019

solved odoo redirect loop nginx ssl


1. proxy mode = true
2. url base = http
3. redirect to logout

if ($query_string ~ "^(.*)redirect=(.*)$") {
       set $args '';
       rewrite ^(.*)$ https://xxx.com/web/session/logout  permanent;

    }

test in HTTPS:

curl -v https://xxx.com/web/login?redirect=http%3A%2F%2Fxxx.com
*   Trying 66.96.239.122...
* TCP_NODELAY set
* Connected to xxx.com (66.96.239.xxx) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/cert.pem
  CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: OU=Domain Control Validated; CN=xxx.com
*  start date: Jun 26 00:51:45 2019 GMT
*  expire date: Jun 26 00:51:45 2020 GMT
*  subjectAltName: host "xxx.com" matched cert's "xxx.com"
*  issuer: C=BE; O=GlobalSign nv-sa; CN=AlphaSSL CA - SHA256 - G2
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x7fe611006400)
> GET /web/login?redirect=http%3A%2F%2Fxxx.com HTTP/2
> Host: xxx.com
> User-Agent: curl/7.54.0
> Accept: */*
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 301 
< server: nginx/1.10.3 (Ubuntu)
< date: Thu, 11 Jul 2019 18:18:56 GMT
< content-type: text/html
< content-length: 194
< location: https://xxx.com/web/session/logout
< strict-transport-security: max-age=31536000; includeSubdomains; preload
< content-security-policy: upgrade-insecure-requests
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.10.3 (Ubuntu)</center>
</body>
</html>

* Connection #0 to host xxx.com left intact

test in HTTP :

curl -v http://xxx.com/web/login?redirect=http%3A%2F%2Fxxx.com
*   Trying 66.96.239.122...
* TCP_NODELAY set
* Connected to xxx.com (66.96.239.xxx) port 80 (#0)
> GET /web/login?redirect=http%3A%2F%2Fxxx.com HTTP/1.1
> Host: xxx.com
> User-Agent: curl/7.54.0
> Accept: */*
< HTTP/1.1 301 Moved Permanently
< Server: nginx/1.10.3 (Ubuntu)
< Date: Thu, 11 Jul 2019 18:27:46 GMT
< Content-Type: text/html
< Content-Length: 194
< Connection: keep-alive
< Location: https://xxx.com/web/session/logout
< Strict-Transport-Security: max-age=2592000
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.10.3 (Ubuntu)</center>
</body>
</html>

* Connection #0 to host xxx.com left intact






Read more ...

Jul 5, 2019

SOLVED, odoo 11, It is not possible to unreserve more products of than you have in stock

just copy paste from Julia,


i had a similar problem, Odoo send me this fix:
ARM created a fix for this. In order to implement it you need to follow these steps:
1.debug mode
2.technical/server actions
3.create
4.action name: e.g. fix unreserved qty
5.model: ir.actions.server
6.action to do: "execute python code"
7.copy/paste the fix underneath the pre-existing code
8."save"
9."create contextual action"
10.refresh page
11.action/fix "fix unreserved qty"
12.wait for it to load
13."remove contextual action"

14.action/delete


here is the code
============
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),
        ('owner_id', '=', quant.owner_id.id),
        ('product_qty', '!=', 0)
    ])
    move_line_ids += move_lines.ids
    reserved_on_move_lines = sum(move_lines.mapped('product_qty'))
    move_line_str = str.join(', ', [str(move_line_id) for move_line_id in move_lines.ids])

    if quant.location_id.should_bypass_reservation():
        # If a quant is in a location that should bypass the reservation, its `reserved_quantity` field
        # should be 0.
        if quant.reserved_quantity != 0:
            quant.write({'reserved_quantity': 0})
    else:
        # If a quant is in a reservable location, its `reserved_quantity` should be exactly the sum
        # of the `product_qty` of all the partially_available / assigned move lines with the same
        # characteristics.
        if quant.reserved_quantity == 0:
            if move_lines:
                move_lines.with_context(bypass_reservation_update=True).write({'product_uom_qty': 0})
        elif quant.reserved_quantity < 0:
            quant.write({'reserved_quantity': 0})
            if move_lines:
                move_lines.with_context(bypass_reservation_update=True).write({'product_uom_qty': 0})
        else:
            if reserved_on_move_lines != quant.reserved_quantity:
                move_lines.with_context(bypass_reservation_update=True).write({'product_uom_qty': 0})
                quant.write({'reserved_quantity': 0})
            else:
              if any(move_line.product_qty < 0 for move_line in move_lines):
                move_lines.with_context(bypass_reservation_update=True).write({'product_uom_qty': 0})
                quant.write({'reserved_quantity': 0})

move_lines = env['stock.move.line'].search([
    ('product_id.type', '=', 'product'),
    ('product_qty', '!=', 0),
    ('id', 'not in', move_line_ids),
])

move_lines_to_unreserve = []

for move_line in move_lines:
    if not move_line.location_id.should_bypass_reservation():
       move_lines_to_unreserve.append(move_line.id)

if len(move_lines_to_unreserve) > 1:
    env.cr.execute(""" UPDATE stock_move_line SET product_uom_qty = 0, product_qty = 0 WHERE id in %s ;""" % (tuple(move_lines_to_unreserve), ))
elif len(move_lines_to_unreserve) == 1:
    env.cr.execute(""" UPDATE stock_move_line SET product_uom_qty = 0, product_qty = 0 WHERE id = %s ;""" % (move_lines_to_unreserve[0]))


then on the logs you will see : 
2019-07-05 15:32:54,032 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2144]
2019-07-05 15:32:54,388 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2145]
2019-07-05 15:32:54,600 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2146]
2019-07-05 15:32:54,814 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2147]
2019-07-05 15:32:55,026 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2148]
2019-07-05 15:32:55,242 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2149]
2019-07-05 15:32:55,458 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2150]
2019-07-05 15:32:55,674 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2151]
2019-07-05 15:32:55,886 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2152]
2019-07-05 15:32:56,095 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2153]
2019-07-05 15:32:56,306 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2154]
2019-07-05 15:32:56,517 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2155]
2019-07-05 15:32:56,736 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2156]
2019-07-05 15:32:56,952 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2157]
2019-07-05 15:32:57,164 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2158]
2019-07-05 15:32:57,378 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2159]
2019-07-05 15:32:57,595 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2160]
2019-07-05 15:32:57,808 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2161]
2019-07-05 15:32:58,023 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2162]
2019-07-05 15:32:58,234 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2163]
2019-07-05 15:32:58,447 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2164]
2019-07-05 15:32:58,654 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2165]
2019-07-05 15:32:58,868 710 INFO dexexp odoo.models.unlink: User #6 deleted stock.move.line records with IDs: [2166]
2019-07-05 15:32:59,081 
Read more ...