Skip to Content
Menu
This question has been flagged
1 Reply
2088 Views

My client has a requirement to set lead times on products, on a per customer basis. For instance:

The product is a search report on coal mining activity in the vicinity of a property. The standard lead time is 5 days.

Customer A asks for a search report on coal mining activity around a property. We really like Customer A, so we have decided that they will have that report within 3 working days. The customer specific lead time should be set to -2 ( 2 days less than standard)

Customer B asks for a search report on coal mining activity around a property. They always pay their bills late, though, so we have secretly decided that they're at the back of the queue - they will have that report within 7 working days. The customer specific lead time should be set to 2 (2 days more than standard)

What I want to do is to add an extra tab to the res.partner view, called Lead Times, and have the product list (including variants) display in a table there. Each row will have 

<tr>
    <td>product name</td>     <td><input type="text" value="a number"></td>
<tr>

This is where I've got to so far:

The model (models/customer.py)

# encoding=utf8
from odoo import fields, api, models
import logging
logging.basicConfig(level=logging.DEBUG)
from datetime import datetime, timedelta
 

class Customer(models.Model):
    _name = 'lead_times'
    partner_id = fields.Many2one('res.partner')
    product_id = fields.Many2one('product.product')
    lead_time = fields.Integer('lead_time')

class MsukPartner(models.Model):
    _inherit = 'res.partner'
    lead_times = fields.Many2one(compute='_get_lead_times', store=False)
    def _get_lead_times(self):
        lead_time_rows = self.env['lead_times'].search([('partner_id', '=', 780)])
        return lead_time_rows

That has produced a table which looks like this:.

miningsearchesuk=# \d lead_times
                                      Table "public.lead_times"
   Column    |            Type             |                        Modifiers                        
-------------+-----------------------------+---------------------------------------------------------
 id          | integer                     | not null default nextval('lead_times_id_seq'::regclass)
 create_uid  | integer                     | 
 product_id  | integer                     | 
 write_uid   | integer                     | 
 write_date  | timestamp without time zone | 
 create_date | timestamp without time zone | 
 partner_id  | integer                     | 
 lead_time   | integer                     | 
Indexes:
    "lead_times_pkey" PRIMARY KEY, btree (id)
Foreign-key constraints:
    "lead_times_create_uid_fkey" FOREIGN KEY (create_uid) REFERENCES res_users(id) ON DELETE SET NULL
    "lead_times_partner_id_fkey" FOREIGN KEY (partner_id) REFERENCES res_partner(id) ON DELETE SET NULL
    "lead_times_product_id_fkey" FOREIGN KEY (product_id) REFERENCES product_product(id) ON DELETE SET NULL
    "lead_times_write_uid_fkey" FOREIGN KEY (write_uid) REFERENCES res_users(id) ON DELETE SET NULL

miningsearchesuk=#


The view (views/res_partner_views.xml)

<odoo>
    <record id="view_partner_msuk_form" model="ir.ui.view">
        <field name="name">res.partner.msuk.form</field>
        <field name="model">res.partner</field>
        <field name="inherit_id" ref="base.view_partner_form" />
        <field name="arch" type="xml">
            <notebook position="inside">
                <page string="Lead Times">
                    <group>
                        <field name="lead_times" />
                        <!--<field name="product_id" />-->
                    </group>
                </page>
            </notebook>
        </field>
    </record>
</odoo>

__init__.py

# -*- encoding: utf-8 -*-

from . import project
from . import product
from . import sale
from . import crm
from . import project_category
from . import product
from . import customer

What I see on screen:


(screenshot deleted as it was causing a 400 error from the forum, I think)


I've created a lead_time entry manually, and set a breakpoint just before _get_lead_times in customer.py. Here's the output:

> /home/miningsearchesuk/src/python/project_template/models/customer.py(21)_get_lead_times()
-> lead_time_rows = self.env['lead_times'].search([('partner_id', '=', 780)])
(Pdb) list
 16
 17         lead_times = fields.Many2one(compute='_get_lead_times', store=False)
 18
 19         def _get_lead_times(self):
 20             import pdb; pdb.set_trace()
 21  ->         lead_time_rows = self.env['lead_times'].search([('partner_id', '=', 780)])
 22             return lead_time_rows
 23
[EOF]
(Pdb) lead_time_rows
*** NameError: name 'lead_time_rows' is not defined
(Pdb) n

> /home/miningsearchesuk/src/python/project_template/models/customer.py(22)_get_lead_times()
-> return lead_time_rows
(Pdb) lead_time_rows
lead_times(1,)
(Pdb) pp lead_time_rows.read([])
[{'__last_update': '2018-07-18 09:53:01',
  'create_date': False,
  'create_uid': False,
  'display_name': u'lead_times,1',
  'id': 1,
  'lead_time': 5,
  'partner_id': (780, u'3MS Construction Ltd'),
  'product_id': (16, u'Further Site Investigation'),
  'write_date': False,
  'write_uid': False}]
(Pdb)

Can anyone give me any hints as to what to do next? How do I get my lead_time_rows to appear as I want?

Thanks

Avatar
Discard
Best Answer

Hello Dominic,

I see that you have put in a lot of efforts on the lines of managing lead times per customer so am not sure if you would like my approach. But have you thought of this like I do:

There is a requested date and a commitment date on the quotation/ Sale order. requested date is something your customer is asking for and commitment date is coming from your system's lead times. Now you have to manage the gaps between the two dates and you would know the customer on your quotation.

Thanks

Vishal

Avatar
Discard
Related Posts Replies Views Activity
4
Apr 20
7555
1
Nov 19
2897
3
Oct 19
6235
2
Feb 18
12053
0
Jan 18
7535