product_supplierinfo_tracking
This commit is contained in:
parent
32ab90c173
commit
e97b7186b1
7 changed files with 231 additions and 0 deletions
3
product_supplierinfo_tracking/__init__.py
Normal file
3
product_supplierinfo_tracking/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import models
|
||||
51
product_supplierinfo_tracking/__manifest__.py
Executable file
51
product_supplierinfo_tracking/__manifest__.py
Executable file
|
|
@ -0,0 +1,51 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
|
||||
{
|
||||
"name": "Product Supplierinfo Tracking",
|
||||
"version": "18.0.2.0.5",
|
||||
"license": "AGPL-3",
|
||||
"author": "Bemade",
|
||||
"category": "Purchase",
|
||||
"depends": [
|
||||
"base",
|
||||
"product",
|
||||
"stock",
|
||||
"sale",
|
||||
"purchase",
|
||||
"mrp",
|
||||
],
|
||||
"description": """
|
||||
This module extends basic inventory and pricelist management in
|
||||
OpenERP to include support for supplierinfo tracking.
|
||||
|
||||
""",
|
||||
"demo": [],
|
||||
'data': [
|
||||
'views/product_view.xml',
|
||||
'views/supplierinfo_pricelist.xml',
|
||||
],
|
||||
'test': [],
|
||||
'installable': True,
|
||||
'active': False
|
||||
}
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
1
product_supplierinfo_tracking/models/__init__.py
Normal file
1
product_supplierinfo_tracking/models/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from . import product_supplierinfo
|
||||
141
product_supplierinfo_tracking/models/product_supplierinfo.py
Executable file
141
product_supplierinfo_tracking/models/product_supplierinfo.py
Executable file
|
|
@ -0,0 +1,141 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import models, fields, api
|
||||
from markupsafe import Markup
|
||||
|
||||
|
||||
class ProductSupplierInfo(models.Model):
|
||||
_name = "product.supplierinfo"
|
||||
_inherit = [
|
||||
"product.supplierinfo",
|
||||
"mail.thread",
|
||||
"mail.activity.mixin"
|
||||
]
|
||||
|
||||
# Commented out because breaking basic Odoo tests. See if this is really needed.
|
||||
|
||||
# _sql_constraints = [("supplierinfo_product_tmpl_id_no_null",
|
||||
# "CHECK((product_tmpl_id IS NOT NULL))",
|
||||
# "Supplier pricelist need product template"),
|
||||
# ]
|
||||
|
||||
# This while avoid the database to save those record with lost product_tmpl_id
|
||||
@api.depends("supplier_list_price", "supplier_discount_percent")
|
||||
def _compute_price(self):
|
||||
for rec in self:
|
||||
rec.price = rec.supplier_list_price - (
|
||||
rec.supplier_list_price * rec.supplier_discount_percent / 100
|
||||
)
|
||||
|
||||
@api.depends("supplier_discount_percent")
|
||||
def _inverse_price(self):
|
||||
for rec in self:
|
||||
discount = (
|
||||
rec.supplier_discount_percent if rec.supplier_discount_percent else 0
|
||||
)
|
||||
rec.supplier_list_price = (100 * rec.price) / (100 - discount)
|
||||
|
||||
partner_id = fields.Many2one(tracking=True, domain=[("is_company", "=", True)])
|
||||
product_name = fields.Char(tracking=True)
|
||||
product_code = fields.Char(tracking=True)
|
||||
product_uom = fields.Many2one(tracking=True)
|
||||
min_qty = fields.Float(tracking=True)
|
||||
currency_id = fields.Many2one(tracking=True)
|
||||
date_start = fields.Date(tracking=True)
|
||||
date_end = fields.Date(tracking=True)
|
||||
product_id = fields.Many2one(tracking=True)
|
||||
product_tmpl_id = fields.Many2one(tracking=True)
|
||||
delay = fields.Integer(tracking=True)
|
||||
|
||||
date_updated = fields.Date(
|
||||
string="Last updated",
|
||||
help="Date at which the supplier " + " list price was last updated.",
|
||||
)
|
||||
|
||||
purchasing_notes = fields.Text(tracking=True, string="Purchasing Notes")
|
||||
|
||||
supplier_list_price = fields.Float(
|
||||
string="Supplier List Price",
|
||||
digits="Product Price",
|
||||
tracking=True,
|
||||
help="""
|
||||
This the supplier list price to which supplier discounts are applied, if
|
||||
any, and the net price if no supplier discounts are to be applied
|
||||
""",
|
||||
)
|
||||
|
||||
supplier_discount_percent = fields.Float(
|
||||
string="Supplier discount (%)", digits="Product Price", tracking=True, default=0
|
||||
)
|
||||
|
||||
price = fields.Float(
|
||||
compute="_compute_price",
|
||||
inverse="_inverse_price",
|
||||
string="Supplier Price",
|
||||
digits="Product Price",
|
||||
help="This price will be considered as a price for the supplier UoM if any or "
|
||||
"the default Unit of Measure of the product otherwise",
|
||||
store=True,
|
||||
)
|
||||
|
||||
def _generate_chatter(self, vals, operation):
|
||||
if len(self) == 1 and self.product_tmpl_id:
|
||||
msg = ""
|
||||
headmsg = (
|
||||
f"<a href='#' data-oe-model='product.supplierinfo' data-oe-id='{self.id}'>"
|
||||
f"Price {operation} for {self.product_id.name} : <br /></a>"
|
||||
)
|
||||
if self.min_qty > 0:
|
||||
msg += f"<li>Minimum qty : {self.min_qty}</li>"
|
||||
if self.date_start:
|
||||
msg += f"<li>Starting : {self.date_start}</li>"
|
||||
if self.date_end:
|
||||
msg += f"<li>Ending : {self.date_end}</li>"
|
||||
if msg:
|
||||
msg = headmsg + "<ul>" + msg + "</ul>"
|
||||
else:
|
||||
msg = headmsg
|
||||
for change in vals:
|
||||
msg += f"{change} --> {vals[change]}<br />"
|
||||
# Should always be there
|
||||
if self.product_tmpl_id:
|
||||
self.product_tmpl_id.message_post(
|
||||
body=Markup(msg),
|
||||
)
|
||||
# only for variant
|
||||
if self.product_id:
|
||||
self.product_id.message_post(body=Markup(msg))
|
||||
|
||||
# Well hard time to set the chatter
|
||||
# def create(self, vals):
|
||||
# res = super(ProductSupplierInfo, self).create(vals)
|
||||
# # # res._generate_chatter(vals, 'create')
|
||||
|
||||
def write(self, vals):
|
||||
res = super(ProductSupplierInfo, self).write(vals)
|
||||
self._generate_chatter(vals, "modify")
|
||||
return res
|
||||
|
||||
def suplierinfo_show_details(self):
|
||||
"""
|
||||
Action to open product.supplierinfo (pricelist) in its own windows and not in a javascript
|
||||
popup to avoid loosing product_tmpl_id. We rely on both context and domain to pass the
|
||||
information
|
||||
"""
|
||||
# views = [(self.env.ref('account.invoice_supplier_tree').id, 'tree'),
|
||||
# (self.env.ref('account.invoice_supplier_form').id, 'form')]
|
||||
return {
|
||||
"name": "Supplier price",
|
||||
"view_type": "form",
|
||||
"view_mode": "form",
|
||||
"res_id": self.id,
|
||||
"context": self.env.context,
|
||||
"res_model": "product.supplierinfo",
|
||||
"domain": [
|
||||
("product_tmpl_id", "=", self.product_tmpl_id),
|
||||
("product_id", "=", self.product_id),
|
||||
],
|
||||
"type": "ir.actions.act_window",
|
||||
# 'view_id': False,
|
||||
# 'views': views,
|
||||
}
|
||||
BIN
product_supplierinfo_tracking/static/description/icon.png
Normal file
BIN
product_supplierinfo_tracking/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
13
product_supplierinfo_tracking/views/product_view.xml
Executable file
13
product_supplierinfo_tracking/views/product_view.xml
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="product_supplierinfo_tree_view_tracking" model="ir.ui.view">
|
||||
<field name="name">product.supplierinfo.list.view2</field>
|
||||
<field name="model">product.supplierinfo</field>
|
||||
<field name="inherit_id" ref="purchase.product_supplierinfo_tree_view2"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//list" position="attributes">
|
||||
<attribute name="open_form_view">1</attribute>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
<record id="product_supplierinfo_form_view_chatter" model="ir.ui.view">
|
||||
<field name="name">supplierinfo.pricelist.chatter</field>
|
||||
<field name="model">product.supplierinfo</field>
|
||||
<field name="inherit_id" ref="product.product_supplierinfo_form_view" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//form/sheet" position="after">
|
||||
<chatter/>
|
||||
</xpath>
|
||||
<label for="price" position="before">
|
||||
<field name="supplier_list_price"/>
|
||||
<field name="supplier_discount_percent"/>
|
||||
</label>
|
||||
<field name="company_id" position="before">
|
||||
<field name="purchasing_notes"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
Loading…
Reference in a new issue