Compare commits
1 Commits
12_sale_pi
...
12-pricel-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2af621083 |
@@ -1,2 +0,0 @@
|
||||
from . import account_invoice
|
||||
from . import account_invoice_report
|
||||
@@ -1,24 +0,0 @@
|
||||
# Copyright 2015-2019 Akretion France (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
'name': 'Account Invoice Margin',
|
||||
'version': '12.0.1.0.0',
|
||||
'category': 'Invoicing Management',
|
||||
'license': 'AGPL-3',
|
||||
'summary': 'Copy standard price on invoice line and compute margins',
|
||||
'description': """
|
||||
This module copies the field *standard_price* of the product on the invoice line when the invoice line is created. The allows the computation of the margin of the invoice.
|
||||
|
||||
This module has been written by Alexis de Lattre from Akretion
|
||||
<alexis.delattre@akretion.com>.
|
||||
""",
|
||||
'author': 'Akretion',
|
||||
'website': 'http://www.akretion.com',
|
||||
'depends': ['account'],
|
||||
'data': [
|
||||
'account_invoice_view.xml',
|
||||
],
|
||||
'installable': True,
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
# Copyright 2015-2019 Akretion France (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
import odoo.addons.decimal_precision as dp
|
||||
|
||||
|
||||
class AccountInvoiceLine(models.Model):
|
||||
_inherit = 'account.invoice.line'
|
||||
|
||||
standard_price_company_currency = fields.Float(
|
||||
string='Cost Price in Company Currency', readonly=True,
|
||||
digits=dp.get_precision('Product Price'),
|
||||
help="Cost price in company currency in the unit of measure "
|
||||
"of the invoice line (which may be different from the unit "
|
||||
"of measure of the product).")
|
||||
standard_price_invoice_currency = fields.Float(
|
||||
string='Cost Price in Invoice Currency', readonly=True,
|
||||
compute='_compute_margin', store=True,
|
||||
digits=dp.get_precision('Product Price'),
|
||||
help="Cost price in invoice currency in the unit of measure "
|
||||
"of the invoice line")
|
||||
margin_invoice_currency = fields.Monetary(
|
||||
string='Margin in Invoice Currency', readonly=True, store=True,
|
||||
compute='_compute_margin', currency_field='currency_id')
|
||||
margin_company_currency = fields.Monetary(
|
||||
string='Margin in Company Currency', readonly=True, store=True,
|
||||
compute='_compute_margin', currency_field='company_currency_id')
|
||||
margin_rate = fields.Float(
|
||||
string="Margin Rate", readonly=True, store=True,
|
||||
compute='_compute_margin',
|
||||
digits=(16, 2), help="Margin rate in percentage of the sale price")
|
||||
|
||||
@api.depends(
|
||||
'standard_price_company_currency', 'invoice_id.currency_id',
|
||||
'invoice_id.type', 'invoice_id.company_id',
|
||||
'invoice_id.date_invoice', 'quantity', 'price_subtotal')
|
||||
def _compute_margin(self):
|
||||
for il in self:
|
||||
standard_price_inv_cur = 0.0
|
||||
margin_inv_cur = 0.0
|
||||
margin_comp_cur = 0.0
|
||||
margin_rate = 0.0
|
||||
inv = il.invoice_id
|
||||
if inv and inv.type in ('out_invoice', 'out_refund'):
|
||||
# it works in _get_current_rate
|
||||
# even if we set date = False in context
|
||||
# standard_price_inv_cur is in the UoM of the invoice line
|
||||
date = inv._get_currency_rate_date() or\
|
||||
fields.Date.context_today(self)
|
||||
company = inv.company_id
|
||||
company_currency = company.currency_id
|
||||
standard_price_inv_cur =\
|
||||
company_currency._convert(
|
||||
il.standard_price_company_currency,
|
||||
inv.currency_id, company, date)
|
||||
margin_inv_cur =\
|
||||
il.price_subtotal - il.quantity * standard_price_inv_cur
|
||||
margin_comp_cur = inv.currency_id._convert(
|
||||
margin_inv_cur, company_currency, company, date)
|
||||
if il.price_subtotal:
|
||||
margin_rate = 100 * margin_inv_cur / il.price_subtotal
|
||||
# for a refund, margin should be negative
|
||||
# but margin rate should stay positive
|
||||
if inv.type == 'out_refund':
|
||||
margin_inv_cur *= -1
|
||||
margin_comp_cur *= -1
|
||||
il.standard_price_invoice_currency = standard_price_inv_cur
|
||||
il.margin_invoice_currency = margin_inv_cur
|
||||
il.margin_company_currency = margin_comp_cur
|
||||
il.margin_rate = margin_rate
|
||||
|
||||
# We want to copy standard_price on invoice line for customer
|
||||
# invoice/refunds. We can't do that via on_change of product_id,
|
||||
# because it is not always played when invoice is created from code
|
||||
# => we inherit write/create
|
||||
# We write standard_price_company_currency even on supplier invoice/refunds
|
||||
# because we don't have access to the 'type' of the invoice
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
if vals.get('product_id'):
|
||||
pp = self.env['product.product'].browse(vals['product_id'])
|
||||
std_price = pp.standard_price
|
||||
inv_uom_id = vals.get('uom_id')
|
||||
if inv_uom_id and inv_uom_id != pp.uom_id.id:
|
||||
inv_uom = self.env['uom.uom'].browse(inv_uom_id)
|
||||
std_price = pp.uom_id._compute_price(
|
||||
std_price, inv_uom)
|
||||
vals['standard_price_company_currency'] = std_price
|
||||
return super(AccountInvoiceLine, self).create(vals)
|
||||
|
||||
def write(self, vals):
|
||||
if not vals:
|
||||
vals = {}
|
||||
if 'product_id' in vals or 'uom_id' in vals:
|
||||
for il in self:
|
||||
if 'product_id' in vals:
|
||||
if vals.get('product_id'):
|
||||
pp = self.env['product.product'].browse(
|
||||
vals['product_id'])
|
||||
else:
|
||||
pp = False
|
||||
else:
|
||||
pp = il.product_id or False
|
||||
# uom_id is NOT a required field
|
||||
if 'uom_id' in vals:
|
||||
if vals.get('uom_id'):
|
||||
inv_uom = self.env['uom.uom'].browse(
|
||||
vals['uom_id'])
|
||||
else:
|
||||
inv_uom = False
|
||||
else:
|
||||
inv_uom = il.uom_id or False
|
||||
std_price = 0.0
|
||||
if pp:
|
||||
std_price = pp.standard_price
|
||||
if inv_uom and inv_uom != pp.uom_id:
|
||||
std_price = pp.uom_id._compute_price(
|
||||
std_price, inv_uom)
|
||||
il.write({'standard_price_company_currency': std_price})
|
||||
return super(AccountInvoiceLine, self).write(vals)
|
||||
|
||||
|
||||
class AccountInvoice(models.Model):
|
||||
_inherit = 'account.invoice'
|
||||
|
||||
margin_invoice_currency = fields.Monetary(
|
||||
string='Margin in Invoice Currency',
|
||||
compute='_compute_margin', store=True, readonly=True,
|
||||
currency_field='currency_id')
|
||||
margin_company_currency = fields.Monetary(
|
||||
string='Margin in Company Currency',
|
||||
compute='_compute_margin', store=True, readonly=True,
|
||||
currency_field='company_currency_id')
|
||||
|
||||
@api.depends(
|
||||
'type',
|
||||
'invoice_line_ids.margin_invoice_currency',
|
||||
'invoice_line_ids.margin_company_currency')
|
||||
def _compute_margin(self):
|
||||
res = self.env['account.invoice.line'].read_group(
|
||||
[('invoice_id', 'in', self.ids)],
|
||||
['invoice_id', 'margin_invoice_currency',
|
||||
'margin_company_currency'],
|
||||
['invoice_id'])
|
||||
for re in res:
|
||||
if re['invoice_id']:
|
||||
inv = self.browse(re['invoice_id'][0])
|
||||
if inv.type in ('out_invoice', 'out_refund'):
|
||||
inv.margin_invoice_currency = re['margin_invoice_currency']
|
||||
inv.margin_company_currency = re['margin_company_currency']
|
||||
@@ -1,60 +0,0 @@
|
||||
# Copyright 2018-2019 Akretion France (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class AccountInvoiceReport(models.Model):
|
||||
_inherit = 'account.invoice.report'
|
||||
|
||||
margin = fields.Float(string='Margin', readonly=True)
|
||||
# why digits=0 ??? Why is it like that in the native "account" module
|
||||
user_currency_margin = fields.Float(
|
||||
string="Margin", compute='_compute_user_currency_margin', digits=0)
|
||||
|
||||
_depends = {
|
||||
'account.invoice': [
|
||||
'account_id', 'amount_total_company_signed',
|
||||
'commercial_partner_id', 'company_id',
|
||||
'currency_id', 'date_due', 'date_invoice', 'fiscal_position_id',
|
||||
'journal_id', 'number', 'partner_bank_id', 'partner_id',
|
||||
'payment_term_id', 'residual', 'state', 'type', 'user_id',
|
||||
],
|
||||
'account.invoice.line': [
|
||||
'account_id', 'invoice_id', 'price_subtotal', 'product_id',
|
||||
'quantity', 'uom_id', 'account_analytic_id',
|
||||
'margin_company_currency',
|
||||
],
|
||||
'product.product': ['product_tmpl_id'],
|
||||
'product.template': ['categ_id'],
|
||||
'uom.uom': ['category_id', 'factor', 'name', 'uom_type'],
|
||||
'res.currency.rate': ['currency_id', 'name'],
|
||||
'res.partner': ['country_id'],
|
||||
}
|
||||
|
||||
@api.depends('currency_id', 'date', 'margin')
|
||||
def _compute_user_currency_margin(self):
|
||||
user_currency = self.env.user.company_id.currency_id
|
||||
currency_rate = self.env['res.currency.rate'].search([
|
||||
('rate', '=', 1),
|
||||
'|',
|
||||
('company_id', '=', self.env.user.company_id.id),
|
||||
('company_id', '=', False)], limit=1)
|
||||
base_currency = currency_rate.currency_id
|
||||
for record in self:
|
||||
date = record.date or fields.Date.today()
|
||||
company = record.company_id
|
||||
record.user_currency_margin = base_currency._convert(
|
||||
record.margin, user_currency, company, date)
|
||||
|
||||
# TODO check for refunds
|
||||
def _sub_select(self):
|
||||
select_str = super(AccountInvoiceReport, self)._sub_select()
|
||||
select_str += ", SUM(ail.margin_company_currency) AS margin"
|
||||
return select_str
|
||||
|
||||
def _select(self):
|
||||
select_str = super(AccountInvoiceReport, self)._select()
|
||||
select_str += ", sub.margin AS margin"
|
||||
return select_str
|
||||
@@ -1,51 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
© 2015-2017 Akretion (http://www.akretion.com/)
|
||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
<odoo>
|
||||
|
||||
<record id="view_invoice_line_form" model="ir.ui.view">
|
||||
<field name="name">margin.account.invoice.line.form</field>
|
||||
<field name="model">account.invoice.line</field>
|
||||
<field name="inherit_id" ref="account.view_invoice_line_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='analytic_tag_ids']/.." position="inside">
|
||||
<field name="standard_price_company_currency"
|
||||
string="Cost Price in Comp. Cur."
|
||||
groups="base.group_no_one"/>
|
||||
<field name="standard_price_invoice_currency"
|
||||
string="Cost Price in Inv. Cur."
|
||||
groups="base.group_no_one"/>
|
||||
<field name="margin_invoice_currency"
|
||||
string="Margin in Inv. Cur."
|
||||
groups="base.group_no_one"/>
|
||||
<field name="margin_company_currency"
|
||||
string="Margin in Comp. Cur."
|
||||
groups="base.group_no_one"/>
|
||||
<label for="margin_rate" groups="base.group_no_one"/>
|
||||
<div name="margin_rate" groups="base.group_no_one">
|
||||
<field name="margin_rate" class="oe_inline"/> %
|
||||
</div>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="invoice_form" model="ir.ui.view">
|
||||
<field name="name">margin.account.invoice.form</field>
|
||||
<field name="model">account.invoice</field>
|
||||
<field name="inherit_id" ref="account.invoice_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="move_id" position="after">
|
||||
<field name="margin_invoice_currency"
|
||||
string="Margin in Inv. Cur." groups="base.group_no_one"/>
|
||||
<field name="margin_company_currency"
|
||||
string="Margin in Comp. Cur." groups="base.group_no_one"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</odoo>
|
||||
@@ -1,39 +0,0 @@
|
||||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
|
||||
:target: https://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||
:alt: License: AGPL-3
|
||||
|
||||
Account Invoice Update Wizard
|
||||
=============================
|
||||
|
||||
This module adds a button *Update Invoice* on Customer and Supplier invoices in
|
||||
Open or Paid state. This button starts a wizard which allows the user to update
|
||||
non-legal fields of the invoice:
|
||||
|
||||
* Source Document
|
||||
* Reference/Description
|
||||
* Payment terms (update allowed only to a payment term with same number of terms
|
||||
of the same amount and on invoices without any payment)
|
||||
* Bank Account
|
||||
* Salesman
|
||||
* Notes
|
||||
* Description of invoice lines
|
||||
* Analytic account
|
||||
* Analytic tags
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
Bugs are tracked on `GitHub Issues
|
||||
<https://github.com/akretion/odoo-usability/issues>`_. In case of trouble, please
|
||||
check there if your issue has already been reported. If you spotted it first,
|
||||
help us smash it by providing detailed and welcomed feedback.
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
* Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
* Florian da Costa <florian.dacosta@akretion.com>
|
||||
* Matthieu Dietrich <matthieu.dietrich@camptocamp.com>
|
||||
* Yannick Vaucher <yannick.vaucher@camptocamp.com>
|
||||
* Mykhailo Panarin <m.panarin@mobilunity.com>
|
||||
* Artem Kostyuk <a.kostyuk@mobilunity.com>
|
||||
@@ -1,2 +0,0 @@
|
||||
from . import models
|
||||
from . import wizard
|
||||
@@ -1,21 +0,0 @@
|
||||
# Copyright 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
# Copyright 2018-2019 Camptocamp
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
'name': 'Account Invoice Update Wizard',
|
||||
'version': '12.0.1.0.0',
|
||||
'category': 'Accounting & Finance',
|
||||
'license': 'AGPL-3',
|
||||
'summary': 'Wizard to update non-legal fields of an open/paid invoice',
|
||||
'author': 'Akretion',
|
||||
'website': 'https://github.com/akretion/odoo-usability',
|
||||
'depends': [
|
||||
'account',
|
||||
],
|
||||
'data': [
|
||||
'wizard/account_invoice_update_view.xml',
|
||||
'views/account_invoice.xml',
|
||||
],
|
||||
'installable': True,
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
from . import account_invoice
|
||||
@@ -1,22 +0,0 @@
|
||||
# Copyright 2019 Camptocamp
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import UserError
|
||||
import odoo.addons.decimal_precision as dp
|
||||
|
||||
|
||||
class AccountInvoice(models.Model):
|
||||
_inherit = 'account.invoice'
|
||||
|
||||
def prepare_update_wizard(self):
|
||||
self.ensure_one()
|
||||
wizard = self.env['account.invoice.update']
|
||||
res = wizard._prepare_default_get(self)
|
||||
action = self.env.ref(
|
||||
'account_invoice_update_wizard.account_invoice_update_action'
|
||||
).read()[0]
|
||||
action['name'] = "Update Wizard"
|
||||
action['res_id'] = wizard.create(res).id
|
||||
return action
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
from . import test_account_invoice_update_wizard
|
||||
@@ -1,196 +0,0 @@
|
||||
# Copyright 2018-2019 Camptocamp
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo.tests.common import SavepointCase
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class TestAccountInvoiceUpdateWizard(SavepointCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.customer12 = cls.env.ref('base.res_partner_12')
|
||||
cls.product16 = cls.env.ref('product.product_product_16')
|
||||
cls.product24 = cls.env.ref('product.product_product_24')
|
||||
uom_unit = cls.env.ref('uom.product_uom_categ_unit')
|
||||
|
||||
cls.invoice1 = cls.env['account.invoice'].create({
|
||||
'name': 'Test invoice',
|
||||
'partner_id': cls.customer12.id,
|
||||
})
|
||||
cls.inv_line1 = cls.env['account.invoice.line'].create({
|
||||
'invoice_id': cls.invoice1.id,
|
||||
'name': "Line1",
|
||||
'product_id': cls.product16.id,
|
||||
'product_uom_id': uom_unit.id,
|
||||
'account_id': cls.invoice1.account_id.id,
|
||||
'price_unit': 42.0,
|
||||
})
|
||||
cls.inv_line2 = cls.env['account.invoice.line'].create({
|
||||
'invoice_id': cls.invoice1.id,
|
||||
'name': "Line2",
|
||||
'product_id': cls.product24.id,
|
||||
'product_uom_id': uom_unit.id,
|
||||
'account_id': cls.invoice1.account_id.id,
|
||||
'price_unit': 1111.1,
|
||||
})
|
||||
|
||||
cls.aa1 = cls.env.ref('analytic.analytic_partners_camp_to_camp')
|
||||
cls.aa2 = cls.env.ref('analytic.analytic_nebula')
|
||||
cls.atag1 = cls.env.ref('analytic.tag_contract')
|
||||
cls.atag2 = cls.env['account.analytic.tag'].create({
|
||||
'name': 'の',
|
||||
})
|
||||
|
||||
def create_wizard(self, invoice):
|
||||
res = self.invoice1.prepare_update_wizard()
|
||||
self.wiz = self.env['account.invoice.update'].browse(res['res_id'])
|
||||
|
||||
def test_add_analytic_account_line1(self):
|
||||
""" Add analytic account on an invoice line
|
||||
after the invoice has been approved.
|
||||
|
||||
This will:
|
||||
- update the move line
|
||||
- create a new analytic line.
|
||||
"""
|
||||
self.invoice1.action_invoice_open()
|
||||
self.create_wizard(self.invoice1)
|
||||
|
||||
wiz_line = self.wiz.line_ids.filtered(
|
||||
lambda rec: rec.invoice_line_id == self.inv_line1)
|
||||
wiz_line.account_analytic_id = self.aa1
|
||||
self.wiz.run()
|
||||
|
||||
related_ml = self.invoice1.move_id.line_ids.filtered(
|
||||
lambda rec: rec.product_id == self.product16)
|
||||
self.assertEqual(related_ml.analytic_account_id, self.aa1)
|
||||
self.assertEqual(related_ml.analytic_line_ids.account_id, self.aa1)
|
||||
|
||||
def test_change_analytic_account_line1(self):
|
||||
""" Change analytic account on an invoice line
|
||||
after the invoice has been approved.
|
||||
|
||||
This will:
|
||||
- update the move line
|
||||
- update the existing analytic line."""
|
||||
self.inv_line1.account_analytic_id = self.aa2
|
||||
|
||||
self.invoice1.action_invoice_open()
|
||||
self.create_wizard(self.invoice1)
|
||||
|
||||
wiz_line = self.wiz.line_ids.filtered(
|
||||
lambda rec: rec.invoice_line_id == self.inv_line1)
|
||||
wiz_line.account_analytic_id = self.aa1
|
||||
self.wiz.run()
|
||||
|
||||
related_ml = self.invoice1.move_id.line_ids.filtered(
|
||||
lambda rec: rec.product_id == self.product16)
|
||||
self.assertEqual(related_ml.analytic_account_id, self.aa1)
|
||||
self.assertEqual(related_ml.analytic_line_ids.account_id, self.aa1)
|
||||
|
||||
def test_error_grouped_move_lines(self):
|
||||
""" Change analytic account on an invoice line
|
||||
after the invoice has been approved where both
|
||||
lines were grouped in the same move line.
|
||||
|
||||
This will raise an error.
|
||||
"""
|
||||
self.invoice1.journal_id.group_invoice_lines = True
|
||||
|
||||
self.inv_line2.product_id = self.product16
|
||||
self.inv_line2.unit_price = 42.0
|
||||
|
||||
self.invoice1.action_invoice_open()
|
||||
self.create_wizard(self.invoice1)
|
||||
|
||||
line1 = self.wiz.line_ids[0]
|
||||
line1.account_analytic_id = self.aa1
|
||||
with self.assertRaises(UserError):
|
||||
self.wiz.run()
|
||||
|
||||
def test_add_analytic_tags_line1(self):
|
||||
""" Add analytic tags on an invoice line
|
||||
after the invoice has been approved.
|
||||
|
||||
This will update move line.
|
||||
"""
|
||||
self.invoice1.action_invoice_open()
|
||||
self.create_wizard(self.invoice1)
|
||||
|
||||
wiz_line = self.wiz.line_ids.filtered(
|
||||
lambda rec: rec.invoice_line_id == self.inv_line1)
|
||||
wiz_line.analytic_tag_ids = self.atag2
|
||||
self.wiz.run()
|
||||
|
||||
related_ml = self.invoice1.move_id.line_ids.filtered(
|
||||
lambda rec: rec.product_id == self.product16)
|
||||
self.assertEqual(related_ml.analytic_tag_ids, self.atag2)
|
||||
self.assertFalse(related_ml.analytic_line_ids)
|
||||
|
||||
def test_change_analytic_tags_line1(self):
|
||||
""" Change analytic tags on an invoice line
|
||||
after the invoice has been approved.
|
||||
|
||||
It will update move line and analytic line
|
||||
"""
|
||||
self.inv_line1.account_analytic_id = self.aa2
|
||||
self.inv_line1.analytic_tag_ids = self.atag1
|
||||
|
||||
self.invoice1.action_invoice_open()
|
||||
self.create_wizard(self.invoice1)
|
||||
|
||||
wiz_line = self.wiz.line_ids.filtered(
|
||||
lambda rec: rec.invoice_line_id == self.inv_line1)
|
||||
wiz_line.analytic_tag_ids = self.atag2
|
||||
self.wiz.run()
|
||||
|
||||
related_ml = self.invoice1.move_id.line_ids.filtered(
|
||||
lambda rec: rec.product_id == self.product16)
|
||||
self.assertEqual(related_ml.analytic_tag_ids, self.atag2)
|
||||
self.assertEqual(related_ml.analytic_line_ids.tag_ids, self.atag2)
|
||||
|
||||
def test_add_analytic_info_line1(self):
|
||||
""" Add analytic account and tags on an invoice line
|
||||
after the invoice has been approved.
|
||||
|
||||
This will:
|
||||
- update move line
|
||||
- create an analytic line
|
||||
"""
|
||||
self.invoice1.action_invoice_open()
|
||||
self.create_wizard(self.invoice1)
|
||||
|
||||
wiz_line = self.wiz.line_ids.filtered(
|
||||
lambda rec: rec.invoice_line_id == self.inv_line1)
|
||||
wiz_line.account_analytic_id = self.aa1
|
||||
wiz_line.analytic_tag_ids = self.atag2
|
||||
self.wiz.run()
|
||||
|
||||
related_ml = self.invoice1.move_id.line_ids.filtered(
|
||||
lambda rec: rec.product_id == self.product16)
|
||||
self.assertEqual(related_ml.analytic_account_id, self.aa1)
|
||||
self.assertEqual(related_ml.analytic_tag_ids, self.atag2)
|
||||
self.assertEqual(related_ml.analytic_line_ids.account_id, self.aa1)
|
||||
self.assertEqual(related_ml.analytic_line_ids.tag_ids, self.atag2)
|
||||
|
||||
def test_empty_analytic_account_line1(self):
|
||||
""" Remove analytic account
|
||||
after the invoice has been approved.
|
||||
|
||||
This will raise an error as it is not implemented.
|
||||
"""
|
||||
self.inv_line1.account_analytic_id = self.aa2
|
||||
|
||||
self.invoice1.action_invoice_open()
|
||||
self.create_wizard(self.invoice1)
|
||||
|
||||
wiz_line = self.wiz.line_ids.filtered(
|
||||
lambda rec: rec.invoice_line_id == self.inv_line1)
|
||||
wiz_line.account_analytic_id = False
|
||||
self.wiz.run()
|
||||
related_ml = self.invoice1.move_id.line_ids.filtered(
|
||||
lambda rec: rec.product_id == self.product16)
|
||||
self.assertFalse(related_ml.analytic_account_id)
|
||||
self.assertFalse(related_ml.analytic_line_ids)
|
||||
@@ -1,29 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
<odoo>
|
||||
|
||||
<record id="invoice_supplier_form" model="ir.ui.view">
|
||||
<field name="model">account.invoice</field>
|
||||
<field name="inherit_id" ref="account.invoice_supplier_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<button name="action_invoice_draft" position="before">
|
||||
<button name="prepare_update_wizard" type="object" string="Update Invoice" states="open,paid" groups="account.group_account_invoice"/>
|
||||
</button>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="invoice_form" model="ir.ui.view">
|
||||
<field name="model">account.invoice</field>
|
||||
<field name="inherit_id" ref="account.invoice_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<button name="action_invoice_draft" position="before">
|
||||
<button name="prepare_update_wizard" type="object" string="Update Invoice" states="open,paid" groups="account.group_account_invoice"/>
|
||||
</button>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -1 +0,0 @@
|
||||
from . import account_invoice_update
|
||||
@@ -1,302 +0,0 @@
|
||||
# Copyright 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
# Copyright 2018-2019 Camptocamp
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import UserError
|
||||
import odoo.addons.decimal_precision as dp
|
||||
|
||||
|
||||
class AccountInvoiceUpdate(models.TransientModel):
|
||||
_name = 'account.invoice.update'
|
||||
_description = 'Wizard to update non-legal fields of invoice'
|
||||
|
||||
invoice_id = fields.Many2one(
|
||||
'account.invoice', string='Invoice', required=True,
|
||||
readonly=True)
|
||||
type = fields.Selection(related='invoice_id.type', readonly=True)
|
||||
company_id = fields.Many2one(
|
||||
related='invoice_id.company_id', readonly=True)
|
||||
partner_id = fields.Many2one(
|
||||
related='invoice_id.partner_id', readonly=True)
|
||||
user_id = fields.Many2one('res.users', string='Salesperson')
|
||||
payment_term_id = fields.Many2one(
|
||||
'account.payment.term', string='Payment Term')
|
||||
reference = fields.Char(string='Invoice Reference')
|
||||
name = fields.Char(string='Reference/Description')
|
||||
origin = fields.Char(string='Source Document')
|
||||
comment = fields.Text('Additional Information')
|
||||
partner_bank_id = fields.Many2one(
|
||||
'res.partner.bank', string='Bank Account')
|
||||
line_ids = fields.One2many(
|
||||
'account.invoice.line.update', 'parent_id', string='Invoice Lines')
|
||||
|
||||
@api.model
|
||||
def _simple_fields2update(self):
|
||||
'''List boolean, date, datetime, char, text fields'''
|
||||
return ['reference', 'name', 'origin', 'comment']
|
||||
|
||||
@api.model
|
||||
def _m2o_fields2update(self):
|
||||
return ['payment_term_id', 'user_id', 'partner_bank_id']
|
||||
|
||||
@api.model
|
||||
def _prepare_default_get(self, invoice):
|
||||
res = {'invoice_id': invoice.id, 'line_ids': []}
|
||||
for sfield in self._simple_fields2update():
|
||||
res[sfield] = invoice[sfield]
|
||||
for m2ofield in self._m2o_fields2update():
|
||||
res[m2ofield] = invoice[m2ofield].id or False
|
||||
for line in invoice.invoice_line_ids:
|
||||
aa_tags = line.analytic_tag_ids
|
||||
aa_tags = [(6, 0, aa_tags.ids)] if aa_tags else False
|
||||
res['line_ids'].append([0, 0, {
|
||||
'invoice_line_id': line.id,
|
||||
'name': line.name,
|
||||
'quantity': line.quantity,
|
||||
'price_subtotal': line.price_subtotal,
|
||||
'account_analytic_id': line.account_analytic_id.id,
|
||||
'analytic_tag_ids': aa_tags,
|
||||
'display_type': line.display_type,
|
||||
}])
|
||||
return res
|
||||
|
||||
@api.onchange('type')
|
||||
def type_on_change(self):
|
||||
res = {'domain': {}}
|
||||
if self.type in ('out_invoice', 'out_refund'):
|
||||
res['domain']['partner_bank_id'] =\
|
||||
"[('partner_id.ref_company_ids', 'in', [company_id])]"
|
||||
else:
|
||||
res['domain']['partner_bank_id'] =\
|
||||
"[('partner_id', '=', partner_id)]"
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def _prepare_invoice(self):
|
||||
vals = {}
|
||||
inv = self.invoice_id
|
||||
for sfield in self._simple_fields2update():
|
||||
if self[sfield] != inv[sfield]:
|
||||
vals[sfield] = self[sfield]
|
||||
for m2ofield in self._m2o_fields2update():
|
||||
if self[m2ofield] != inv[m2ofield]:
|
||||
vals[m2ofield] = self[m2ofield].id or False
|
||||
if 'payment_term_id' in vals:
|
||||
pterm_list = self.payment_term_id.compute(
|
||||
value=1, date_ref=inv.date_invoice)[0]
|
||||
if pterm_list:
|
||||
vals['date_due'] = max(line[0] for line in pterm_list)
|
||||
return vals
|
||||
|
||||
@api.model
|
||||
def _line_simple_fields2update(self):
|
||||
return ["name",]
|
||||
|
||||
@api.model
|
||||
def _line_m2o_fields2update(self):
|
||||
return ["account_analytic_id",]
|
||||
|
||||
@api.model
|
||||
def _line_m2m_fields2update(self):
|
||||
return ["analytic_tag_ids",]
|
||||
|
||||
@api.model
|
||||
def _prepare_invoice_line(self, line):
|
||||
vals = {}
|
||||
for field in self._line_simple_fields2update():
|
||||
if line[field] != line.invoice_line_id[field]:
|
||||
vals[field] = line[field]
|
||||
for field in self._line_m2o_fields2update():
|
||||
if line[field] != line.invoice_line_id[field]:
|
||||
vals[field] = line[field].id
|
||||
for field in self._line_m2m_fields2update():
|
||||
if line[field] != line.invoice_line_id[field]:
|
||||
vals[field] = [(6, 0, line[field].ids)]
|
||||
return vals
|
||||
|
||||
@api.multi
|
||||
def _prepare_move(self):
|
||||
mvals = {}
|
||||
inv = self.invoice_id
|
||||
ini_ref = inv.move_id.ref
|
||||
ref = inv.reference or inv.name
|
||||
if ini_ref != ref:
|
||||
mvals['ref'] = ref
|
||||
return mvals
|
||||
|
||||
@api.multi
|
||||
def _get_matching_inv_line(self, move_line):
|
||||
""" Find matching invoice line by product """
|
||||
# TODO make it accept more case as lines won't
|
||||
# be grouped unless journal.group_invoice_line is True
|
||||
inv_line = self.invoice_id.invoice_line_ids.filtered(
|
||||
lambda rec: rec.product_id == move_line.product_id)
|
||||
if len(inv_line) != 1:
|
||||
raise UserError(
|
||||
"Cannot match a single invoice line to move line %s" %
|
||||
move_line.name)
|
||||
return inv_line
|
||||
|
||||
@api.multi
|
||||
def _prepare_move_line(self, inv_line):
|
||||
mlvals = {}
|
||||
inv_line_upd = self.line_ids.filtered(
|
||||
lambda rec: rec.invoice_line_id == inv_line)
|
||||
|
||||
ini_aa = inv_line.account_analytic_id
|
||||
new_aa = inv_line_upd.account_analytic_id
|
||||
|
||||
if ini_aa != new_aa:
|
||||
mlvals['analytic_account_id'] = new_aa.id
|
||||
|
||||
ini_aa_tags = inv_line.analytic_tag_ids
|
||||
new_aa_tags = inv_line_upd.analytic_tag_ids
|
||||
|
||||
if ini_aa_tags != new_aa_tags:
|
||||
mlvals['analytic_tag_ids'] = [(6, None, new_aa_tags.ids)]
|
||||
return mlvals
|
||||
|
||||
@api.multi
|
||||
def _prepare_analytic_line(self, inv_line):
|
||||
alvals = {}
|
||||
inv_line_upd = self.line_ids.filtered(
|
||||
lambda rec: rec.invoice_line_id == inv_line)
|
||||
|
||||
ini_aa = inv_line.account_analytic_id
|
||||
new_aa = inv_line_upd.account_analytic_id
|
||||
|
||||
if ini_aa != new_aa:
|
||||
alvals['account_id'] = new_aa.id
|
||||
|
||||
ini_aa_tags = inv_line.analytic_tag_ids
|
||||
new_aa_tags = inv_line_upd.analytic_tag_ids
|
||||
|
||||
if ini_aa_tags != new_aa_tags:
|
||||
alvals['tag_ids'] = [(6, None, new_aa_tags.ids)]
|
||||
return alvals
|
||||
|
||||
@api.multi
|
||||
def _update_payment_term_move(self):
|
||||
self.ensure_one()
|
||||
inv = self.invoice_id
|
||||
if (
|
||||
self.payment_term_id and
|
||||
self.payment_term_id != inv.payment_term_id and
|
||||
inv.move_id):
|
||||
# I don't update pay term when the invoice is partially (or fully)
|
||||
# paid because if you have a payment term with several lines
|
||||
# of the same amount, you would also have to take into account
|
||||
# the reconcile marks to put the new maturity date on the right
|
||||
# lines
|
||||
if inv.payment_ids:
|
||||
raise UserError(_(
|
||||
"This wizard doesn't support the update of payment "
|
||||
"terms on an invoice which is partially or fully "
|
||||
"paid."))
|
||||
prec = self.env['decimal.precision'].precision_get('Account')
|
||||
term_res = self.payment_term_id.compute(
|
||||
inv.amount_total, inv.date_invoice)[0]
|
||||
new_pterm = {} # key = int(amount * 100), value = [date1, date2]
|
||||
for entry in term_res:
|
||||
amount = int(entry[1] * 10 * prec)
|
||||
if amount in new_pterm:
|
||||
new_pterm[amount].append(entry[0])
|
||||
else:
|
||||
new_pterm[amount] = [entry[0]]
|
||||
mlines = {} # key = int(amount * 100), value : [line1, line2]
|
||||
for line in inv.move_id.line_ids:
|
||||
if line.account_id == inv.account_id:
|
||||
amount = int(abs(line.credit - line.debit) * 10 * prec)
|
||||
if amount in mlines:
|
||||
mlines[amount].append(line)
|
||||
else:
|
||||
mlines[amount] = [line]
|
||||
for iamount, lines in mlines.items():
|
||||
if len(lines) != len(new_pterm.get(iamount, [])):
|
||||
raise UserError(_(
|
||||
"The original payment term '%s' doesn't have the "
|
||||
"same terms (number of terms and/or amount) as the "
|
||||
"new payment term '%s'. You can only switch to a "
|
||||
"payment term that has the same number of terms "
|
||||
"with the same amount.") % (
|
||||
inv.payment_term_id.name, self.payment_term_id.name))
|
||||
for line in lines:
|
||||
line.date_maturity = new_pterm[iamount].pop()
|
||||
|
||||
@api.multi
|
||||
def run(self):
|
||||
self.ensure_one()
|
||||
inv = self.invoice_id
|
||||
updated = False
|
||||
# re-write date_maturity on move line
|
||||
self._update_payment_term_move()
|
||||
ivals = self._prepare_invoice()
|
||||
if ivals:
|
||||
updated = True
|
||||
inv.write(ivals)
|
||||
if inv.move_id:
|
||||
mvals = self._prepare_move()
|
||||
if mvals:
|
||||
inv.move_id.write(mvals)
|
||||
for ml in inv.move_id.line_ids.filtered(
|
||||
# we are only interested in invoice lines, not tax lines
|
||||
lambda rec: bool(rec.product_id)
|
||||
):
|
||||
if ml.credit == 0.0:
|
||||
continue
|
||||
inv_line = self._get_matching_inv_line(ml)
|
||||
mlvals = self._prepare_move_line(inv_line)
|
||||
if mlvals:
|
||||
updated = True
|
||||
ml.write(mlvals)
|
||||
aalines = ml.analytic_line_ids
|
||||
alvals = self._prepare_analytic_line(inv_line)
|
||||
if aalines and alvals:
|
||||
updated = True
|
||||
if ('account_id' in alvals and
|
||||
alvals['account_id'] is False):
|
||||
former_aa = inv_line.account_analytic_id
|
||||
to_remove_aalines = aalines.filtered(
|
||||
lambda rec: rec.account_id == former_aa)
|
||||
# remove existing analytic line
|
||||
to_remove_aalines.unlink()
|
||||
else:
|
||||
aalines.write(alvals)
|
||||
elif 'account_id' in alvals:
|
||||
# Create analytic lines if analytic account
|
||||
# is added later
|
||||
ml.create_analytic_lines()
|
||||
for line in self.line_ids:
|
||||
ilvals = self._prepare_invoice_line(line)
|
||||
if ilvals:
|
||||
updated = True
|
||||
line.invoice_line_id.write(ilvals)
|
||||
if updated:
|
||||
inv.message_post(body=_(
|
||||
'Non-legal fields of invoice updated via the Invoice Update '
|
||||
'wizard.'))
|
||||
return True
|
||||
|
||||
|
||||
class AccountInvoiceLineUpdate(models.TransientModel):
|
||||
_name = 'account.invoice.line.update'
|
||||
_description = 'Update non-legal fields of invoice lines'
|
||||
|
||||
parent_id = fields.Many2one(
|
||||
'account.invoice.update', string='Wizard', ondelete='cascade')
|
||||
invoice_line_id = fields.Many2one(
|
||||
'account.invoice.line', string='Invoice Line', readonly=True)
|
||||
name = fields.Text(string='Description', required=True)
|
||||
display_type = fields.Selection([
|
||||
('line_section', "Section"),
|
||||
('line_note', "Note")], default=False, help="Technical field for UX purpose.")
|
||||
quantity = fields.Float(
|
||||
string='Quantity', digits=dp.get_precision('Product Unit of Measure'),
|
||||
readonly=True)
|
||||
price_subtotal = fields.Float(
|
||||
string='Amount', readonly=True, digits=dp.get_precision('Account'))
|
||||
account_analytic_id = fields.Many2one(
|
||||
'account.analytic.account', string='Analytic Account')
|
||||
analytic_tag_ids = fields.Many2many(
|
||||
'account.analytic.tag', string='Analytic Tags')
|
||||
@@ -1,54 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
© 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
<odoo>
|
||||
|
||||
<record id="account_invoice_update_form" model="ir.ui.view">
|
||||
<field name="model">account.invoice.update</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Update Invoice Wizard">
|
||||
<group name="main">
|
||||
<field name="invoice_id" invisible="1"/>
|
||||
<field name="type" invisible="1"/>
|
||||
<field name="company_id" invisible="1"/>
|
||||
<field name="partner_id" invisible="1"/>
|
||||
<field name="reference" attrs="{'invisible': [('type', 'not in', ('in_invoice', 'in_refund'))]}"/>
|
||||
<field name="origin"/>
|
||||
<field name="name"/>
|
||||
<field name="payment_term_id" widget="selection"/>
|
||||
<field name="partner_bank_id"/>
|
||||
<field name="user_id"/>
|
||||
<field name="comment"/>
|
||||
</group>
|
||||
<group name="lines">
|
||||
<field name="line_ids" nolabel="1">
|
||||
<tree editable="bottom" create="false" delete="false" edit="true">
|
||||
<field name="invoice_line_id" invisible="1"/>
|
||||
<field name="display_type" invisible="1"/>
|
||||
<field name="name"/>
|
||||
<field name="quantity" attrs="{'invisible': [('display_type', '!=', False)]}"/>
|
||||
<field name="price_subtotal" attrs="{'invisible': [('display_type', '!=', False)]}"/>
|
||||
<field name="account_analytic_id" attrs="{'invisible': [('display_type', '!=', False)]}" groups="analytic.group_analytic_accounting"/>
|
||||
<field name="analytic_tag_ids" attrs="{'invisible': [('display_type', '!=', False)]}" groups="analytic.group_analytic_accounting" widget="many2many_tags"/>
|
||||
</tree>
|
||||
</field>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="run" type="object" class="oe_highlight" string="Update"/>
|
||||
<button special="cancel" string="Cancel" class="oe_link"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="account_invoice_update_action" model="ir.actions.act_window">
|
||||
<field name="name">Invoice Update Wizard</field>
|
||||
<field name="res_model">account.invoice.update</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -14,13 +14,10 @@ Account Usability
|
||||
|
||||
The usability enhancements include:
|
||||
* show the supplier invoice number in the tree view of supplier invoices
|
||||
* add an *Overdue* filter on invoice search view (this feature was previously
|
||||
located in te module *account_invoice_overdue_filter*)
|
||||
* increase the default limit of 80 lines in account move and account move line view.
|
||||
* fast search on *Reconcile Ref* for account move line.
|
||||
* add an *Overdue* filter on invoice search view (this feature was previously located in te module *account_invoice_overdue_filter*)
|
||||
* Increase the default limit of 80 lines in account move and account move line view.
|
||||
* Fast search on *Reconcile Ref* for account move line.
|
||||
* disable reconciliation "guessing"
|
||||
* add sale dates to invoice report to be compliant with
|
||||
https://www.service-public.fr/professionnels-entreprises/vosdroits/F31808
|
||||
|
||||
Together with this module, I recommend the use of the following modules:
|
||||
* account_invoice_supplier_ref_unique (OCA project account-invoicing)
|
||||
@@ -43,7 +40,6 @@ This module has been written by Alexis de Lattre from Akretion <alexis.delattre@
|
||||
'account_invoice_report_view.xml',
|
||||
'partner_view.xml',
|
||||
'wizard/account_invoice_mark_sent_view.xml',
|
||||
'report/invoice_report.xml',
|
||||
],
|
||||
'installable': True,
|
||||
}
|
||||
|
||||
@@ -37,10 +37,6 @@ class AccountInvoice(models.Model):
|
||||
has_attachment = fields.Boolean(
|
||||
compute='_compute_has_attachment',
|
||||
search='_search_has_attachment', readonly=True)
|
||||
sale_dates = fields.Char(
|
||||
compute="_compute_sales_dates", readonly=True,
|
||||
help="This information appears on invoice qweb report "
|
||||
"(you may use it for your own report)")
|
||||
|
||||
def _compute_has_discount(self):
|
||||
prec = self.env['decimal.precision'].precision_get('Discount')
|
||||
@@ -174,24 +170,6 @@ class AccountInvoice(models.Model):
|
||||
# ]
|
||||
return res
|
||||
|
||||
def _compute_sales_dates(self):
|
||||
""" French law requires to set sale order dates into invoice
|
||||
returned string: "sale1 (date1), sale2 (date2) ..."
|
||||
"""
|
||||
for inv in self:
|
||||
sales = inv.invoice_line_ids.mapped(
|
||||
'sale_line_ids').mapped('order_id')
|
||||
lang = inv.partner_id.commercial_partner_id.lang
|
||||
date_format = self.env["res.lang"]._lang_get(
|
||||
lang or "").date_format
|
||||
dates = ["%s%s" % (
|
||||
x.name,
|
||||
x.confirmation_date and " (%s)" %
|
||||
# only when confirmation_date display it
|
||||
x.confirmation_date.strftime(date_format) or "")
|
||||
for x in sales]
|
||||
inv.sale_dates = ", ".join(dates)
|
||||
|
||||
|
||||
class AccountInvoiceLine(models.Model):
|
||||
_inherit = 'account.invoice.line'
|
||||
@@ -648,14 +626,3 @@ class AccountReconcileModel(models.Model):
|
||||
# Because it's much better to have the bank statement line label as
|
||||
# label of the counter-part move line, then the label of the button
|
||||
assert True # Stupid line of code just to have something...
|
||||
|
||||
|
||||
class AccountIncoterms(models.Model):
|
||||
_inherit = 'account.incoterms'
|
||||
|
||||
@api.depends('code', 'name')
|
||||
def name_get(self):
|
||||
res = []
|
||||
for rec in self:
|
||||
res.append((rec.id, '[%s] %s' % (rec.code, rec.name)))
|
||||
return res
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
<field name="fiscal_position_id" position="attributes">
|
||||
<attribute name="widget">selection</attribute>
|
||||
</field>
|
||||
<field name="incoterm_id" position="attributes">
|
||||
<attribute name="widget">selection</attribute>
|
||||
</field>
|
||||
<field name="invoice_line_ids" position="before">
|
||||
<button name="delete_lines_qty_zero" states="draft" string="⇒ Delete lines qty=0" type="object" class="oe_link oe_right" groups="account.group_account_invoice"/>
|
||||
</field>
|
||||
@@ -36,9 +33,6 @@
|
||||
<field name="fiscal_position_id" position="attributes">
|
||||
<attribute name="widget">selection</attribute>
|
||||
</field>
|
||||
<field name="incoterm_id" position="attributes">
|
||||
<attribute name="widget">selection</attribute>
|
||||
</field>
|
||||
<!-- move sent field and make it visible -->
|
||||
<field name="sent" position="replace"/>
|
||||
<field name="move_id" position="before">
|
||||
@@ -408,17 +402,6 @@ module -->
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_account_journal_tree" model="ir.ui.view">
|
||||
<field name="name">usability.account.journal.tree</field>
|
||||
<field name="model">account.journal</field>
|
||||
<field name="inherit_id" ref="account.view_account_journal_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="name" position="after">
|
||||
<field name="code"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_account_journal_search" model="ir.ui.view">
|
||||
<field name="name">usability.account.journal.search</field>
|
||||
<field name="model">account.journal</field>
|
||||
@@ -492,17 +475,6 @@ module -->
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- ACCOUNT TAX -->
|
||||
<record id="view_tax_tree" model="ir.ui.view">
|
||||
<field name="model">account.tax</field>
|
||||
<field name="inherit_id" ref="account.view_tax_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="company_id" position="before">
|
||||
<field name="price_include" string="Include"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- ACCOUNT TAX GROUP -->
|
||||
<!-- in the account module, there is nothing for account.tax.group : no form/tree view, no menu... -->
|
||||
<record id="account_tax_group_form" model="ir.ui.view">
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<template id="report_invoice_document" inherit_id="account.report_invoice_document">
|
||||
<xpath expr="//div[@name='origin']/p" position="replace">
|
||||
<p class="m-0" t-field="o.sale_dates"/>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
</odoo>
|
||||
@@ -3,4 +3,3 @@ from . import partner
|
||||
from . import company
|
||||
from . import mail
|
||||
from . import misc
|
||||
from . import ir_model
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
# Copyright 2019 Akretion France (http://www.akretion.com/)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class IrModel(models.Model):
|
||||
_inherit = 'ir.model'
|
||||
|
||||
@api.depends('name', 'model')
|
||||
def name_get(self):
|
||||
res = []
|
||||
for rec in self:
|
||||
res.append((rec.id, '%s (%s)' % (rec.name, rec.model)))
|
||||
return res
|
||||
@@ -1,23 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2015-2019 Akretion France (http://www.akretion.com/)
|
||||
© 2015-2016 Akretion (http://www.akretion.com/)
|
||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
<odoo>
|
||||
|
||||
<record id="module_view_kanban" model="ir.ui.view">
|
||||
<field name="name">Better display of module technical name</field>
|
||||
<field name="model">ir.module.module</field>
|
||||
<field name="inherit_id" ref="base.module_view_kanban"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//h4[@class='o_kanban_record_title']/code[@groups='base.group_no_one']" position="before">
|
||||
<br/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_module_filter" model="ir.ui.view">
|
||||
<field name="model">ir.module.module</field>
|
||||
<field name="inherit_id" ref="base.view_module_filter"/>
|
||||
@@ -35,5 +24,4 @@
|
||||
<field name="context">{'search_default_installable': 1}</field>
|
||||
</record>
|
||||
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
from . import stock
|
||||
@@ -1,29 +0,0 @@
|
||||
# Copyright 2018-2019 Akretion (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
'name': 'Delivery Usability',
|
||||
'version': '12.0.1.0.0',
|
||||
'category': 'Stock',
|
||||
'license': 'AGPL-3',
|
||||
'summary': 'Several usability enhancements in Delivery',
|
||||
'description': """
|
||||
Delivery Usability
|
||||
===================
|
||||
|
||||
The usability enhancements include:
|
||||
* allow modification of carrier and it's tracking ref. on a done picking
|
||||
* display field 'invoice_shipping_on_delivery' on sale.order form view
|
||||
|
||||
This module has been written by Alexis de Lattre from Akretion <alexis.delattre@akretion.com>.
|
||||
""",
|
||||
'author': 'Akretion',
|
||||
'website': 'http://www.akretion.com',
|
||||
'depends': ['delivery'],
|
||||
'data': [
|
||||
'sale_view.xml',
|
||||
'stock_view.xml',
|
||||
],
|
||||
'installable': True,
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2018-2019 Akretion
|
||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
<odoo>
|
||||
|
||||
|
||||
<record id="view_order_form_with_carrier" model="ir.ui.view">
|
||||
<field name="name">delivery_usability.sale.order.form</field>
|
||||
<field name="model">sale.order</field>
|
||||
<field name="inherit_id" ref="delivery.view_order_form_with_carrier"/>
|
||||
<field name="arch" type="xml">
|
||||
<group name="sale_pay" position="inside">
|
||||
<field name="invoice_shipping_on_delivery"/>
|
||||
</group>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</odoo>
|
||||
@@ -1,12 +0,0 @@
|
||||
# Copyright 2018-2019 Akretion (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class StockPicking(models.Model):
|
||||
_inherit = 'stock.picking'
|
||||
|
||||
carrier_id = fields.Many2one(track_visibility='onchange')
|
||||
carrier_tracking_ref = fields.Char(track_visibility='onchange')
|
||||
@@ -1,26 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2018 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
<odoo>
|
||||
|
||||
<record id="view_picking_withcarrier_out_form" model="ir.ui.view">
|
||||
<field name="name">delivery_usability.stock.picking.form</field>
|
||||
<field name="model">stock.picking</field>
|
||||
<field name="inherit_id" ref="delivery.view_picking_withcarrier_out_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="carrier_id" position="attributes">
|
||||
<!-- Sometimes we have to modify carrier_id when state is done
|
||||
so remove readonly when state = done from view and add tracking on_change in
|
||||
field definition -->
|
||||
<attribute name="attrs">{}</attribute>
|
||||
</field>
|
||||
<field name="carrier_tracking_ref" position="attributes">
|
||||
<attribute name="attrs">{}</attribute>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -1 +0,0 @@
|
||||
from .hooks import web_m2x_options_create
|
||||
@@ -1,25 +0,0 @@
|
||||
# Copyright 2014-2019 Akretion France (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
|
||||
{
|
||||
'name': 'Eradicate Quick Create',
|
||||
'version': '12.0.2.0.0',
|
||||
'category': 'Tools',
|
||||
'license': 'AGPL-3',
|
||||
'summary': 'Disable quick create on all objects',
|
||||
'description': """
|
||||
Eradicate Quick Create
|
||||
======================
|
||||
|
||||
Disable quick create on all objects of Odoo.
|
||||
|
||||
This new version of the module uses the module *web_m2x_options* from the OCA *web* project instead of the module *base_optional_quick_create* from the OCA project *server-ux*.
|
||||
|
||||
This module has been written by Alexis de Lattre from Akretion <alexis.delattre@akretion.com>.
|
||||
""",
|
||||
'author': 'Akretion',
|
||||
'website': 'http://www.akretion.com',
|
||||
'depends': ['web_m2x_options'],
|
||||
'post_init_hook': 'web_m2x_options_create',
|
||||
'installable': True,
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
# Copyright 2019 Akretion France
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import SUPERUSER_ID
|
||||
from odoo.api import Environment
|
||||
|
||||
|
||||
def web_m2x_options_create(cr, registry):
|
||||
env = Environment(cr, SUPERUSER_ID, {})
|
||||
config_parameter = env['ir.config_parameter'].search(
|
||||
[('key', '=', 'web_m2x_options.create')])
|
||||
if config_parameter and config_parameter.value != 'False':
|
||||
config_parameter.value = 'False'
|
||||
else:
|
||||
env['ir.config_parameter'].create({
|
||||
'key': 'web_m2x_options.create',
|
||||
'value': 'False',
|
||||
})
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.6 KiB |
@@ -1,3 +1 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import models
|
||||
from . import mrp
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (C) 2016-2019 Akretion (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
@@ -24,10 +25,10 @@ This module has been written by Alexis de Lattre from Akretion <alexis.delattre@
|
||||
'website': 'http://www.akretion.com',
|
||||
'depends': ['mrp'],
|
||||
'data': [
|
||||
'security/mrp_average_cost_security.xml',
|
||||
'mrp_view.xml',
|
||||
'mrp_data.xml',
|
||||
'security/labour_cost_profile_security.xml',
|
||||
'security/ir.model.access.csv',
|
||||
'data/mrp_data.xml',
|
||||
'views/mrp_view.xml',
|
||||
],
|
||||
'installable': True,
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import mrp
|
||||
@@ -1,260 +0,0 @@
|
||||
# Copyright (C) 2016-2019 Akretion (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models, fields, api, _
|
||||
import odoo.addons.decimal_precision as dp
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tools import float_compare, float_is_zero
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MrpBomLabourLine(models.Model):
|
||||
_name = 'mrp.bom.labour.line'
|
||||
_description = 'Labour lines on BOM'
|
||||
|
||||
bom_id = fields.Many2one(
|
||||
comodel_name='mrp.bom',
|
||||
string='Labour Lines',
|
||||
ondelete='cascade')
|
||||
|
||||
labour_time = fields.Float(
|
||||
string='Labour Time',
|
||||
required=True,
|
||||
digits=dp.get_precision('Labour Hours'),
|
||||
help="Average labour time for the production of "
|
||||
"items of the BOM, in hours.")
|
||||
|
||||
labour_cost_profile_id = fields.Many2one(
|
||||
comodel_name='labour.cost.profile',
|
||||
string='Labour Cost Profile',
|
||||
required=True)
|
||||
|
||||
note = fields.Text(
|
||||
string='Note')
|
||||
|
||||
_sql_constraints = [(
|
||||
'labour_time_positive',
|
||||
'CHECK (labour_time >= 0)',
|
||||
"The value of the field 'Labour Time' must be positive or 0.")]
|
||||
|
||||
|
||||
class MrpBom(models.Model):
|
||||
_inherit = 'mrp.bom'
|
||||
|
||||
@api.depends(
|
||||
'labour_line_ids.labour_time',
|
||||
'labour_line_ids.labour_cost_profile_id.hour_cost')
|
||||
def _compute_total_labour_cost(self):
|
||||
for bom in self:
|
||||
cost = 0.0
|
||||
for lline in bom.labour_line_ids:
|
||||
cost += lline.labour_time *\
|
||||
lline.labour_cost_profile_id.hour_cost
|
||||
bom.total_labour_cost = cost
|
||||
|
||||
@api.depends(
|
||||
'bom_line_ids.product_id.standard_price',
|
||||
'total_labour_cost', 'extra_cost')
|
||||
def _compute_total_cost(self):
|
||||
for bom in self:
|
||||
comp_cost = 0.0
|
||||
for line in bom.bom_line_ids:
|
||||
comp_price = line.product_id.standard_price
|
||||
comp_qty_product_uom = line.product_uom_id._compute_quantity(
|
||||
line.product_qty, line.product_id.uom_id)
|
||||
comp_cost += comp_price * comp_qty_product_uom
|
||||
total_cost = comp_cost + bom.extra_cost + bom.total_labour_cost
|
||||
bom.total_components_cost = comp_cost
|
||||
bom.total_cost = total_cost
|
||||
|
||||
labour_line_ids = fields.One2many(
|
||||
'mrp.bom.labour.line', 'bom_id', string='Labour Lines')
|
||||
total_labour_cost = fields.Float(
|
||||
compute='_compute_total_labour_cost', readonly=True,
|
||||
digits=dp.get_precision('Product Price'),
|
||||
string="Total Labour Cost", store=True)
|
||||
extra_cost = fields.Float(
|
||||
string='Extra Cost', track_visibility='onchange',
|
||||
digits=dp.get_precision('Product Price'),
|
||||
help="Extra cost for the production of the quantity of "
|
||||
"items of the BOM, in company currency. "
|
||||
"You can use this field to enter the cost of the consumables "
|
||||
"that are used to produce the product but are not listed in "
|
||||
"the BOM")
|
||||
total_components_cost = fields.Float(
|
||||
compute='_compute_total_cost', readonly=True,
|
||||
digits=dp.get_precision('Product Price'),
|
||||
string='Total Components Cost')
|
||||
total_cost = fields.Float(
|
||||
compute='_compute_total_cost', readonly=True,
|
||||
string='Total Cost',
|
||||
digits=dp.get_precision('Product Price'),
|
||||
help="Total Cost = Total Components Cost + "
|
||||
"Total Labour Cost + Extra Cost")
|
||||
company_currency_id = fields.Many2one(
|
||||
related='company_id.currency_id', string='Company Currency')
|
||||
|
||||
@api.model
|
||||
def _phantom_update_product_standard_price(self):
|
||||
logger.info('Start to auto-update cost price from phantom bom')
|
||||
boms = self.search([('type', '=', 'phantom')])
|
||||
boms.with_context(
|
||||
product_price_history_origin='Automatic update of Phantom BOMs')\
|
||||
.manual_update_product_standard_price()
|
||||
logger.info('End of the auto-update cost price from phantom bom')
|
||||
return True
|
||||
|
||||
def manual_update_product_standard_price(self):
|
||||
if 'product_price_history_origin' not in self._context:
|
||||
self = self.with_context(
|
||||
product_price_history_origin='Manual update from BOM')
|
||||
precision = self.env['decimal.precision'].precision_get(
|
||||
'Product Price')
|
||||
for bom in self:
|
||||
wproduct = bom.product_id
|
||||
if not wproduct:
|
||||
wproduct = bom.product_tmpl_id
|
||||
if float_compare(
|
||||
wproduct.standard_price, bom.total_cost,
|
||||
precision_digits=precision):
|
||||
wproduct.with_context().write(
|
||||
{'standard_price': bom.total_cost})
|
||||
logger.info(
|
||||
'Cost price updated to %s on product %s',
|
||||
bom.total_cost, wproduct.display_name)
|
||||
return True
|
||||
|
||||
|
||||
class MrpBomLine(models.Model):
|
||||
_inherit = 'mrp.bom.line'
|
||||
|
||||
standard_price = fields.Float(
|
||||
related='product_id.standard_price',
|
||||
readonly=True,
|
||||
string='Standard Price')
|
||||
|
||||
|
||||
class LabourCostProfile(models.Model):
|
||||
_name = 'labour.cost.profile'
|
||||
_inherit = ['mail.thread']
|
||||
_description = 'Labour Cost Profile'
|
||||
|
||||
name = fields.Char(
|
||||
string='Name',
|
||||
required=True,
|
||||
track_visibility='onchange')
|
||||
|
||||
hour_cost = fields.Float(
|
||||
string='Cost per Hour',
|
||||
required=True,
|
||||
digits=dp.get_precision('Product Price'),
|
||||
track_visibility='onchange',
|
||||
help="Labour cost per hour per person in company currency")
|
||||
|
||||
company_id = fields.Many2one(
|
||||
comodel_name='res.company',
|
||||
string='Company',
|
||||
required=True,
|
||||
default=lambda self: self.env['res.company']._company_default_get())
|
||||
|
||||
company_currency_id = fields.Many2one(
|
||||
related='company_id.currency_id',
|
||||
readonly=True,
|
||||
store=True,
|
||||
string='Company Currency')
|
||||
|
||||
@api.depends('name', 'hour_cost', 'company_currency_id.symbol')
|
||||
def name_get(self):
|
||||
res = []
|
||||
for record in self:
|
||||
res.append((record.id, u'%s (%s %s)' % (
|
||||
record.name, record.hour_cost,
|
||||
record.company_currency_id.symbol)))
|
||||
return res
|
||||
|
||||
|
||||
class MrpProduction(models.Model):
|
||||
_inherit = 'mrp.production'
|
||||
|
||||
unit_cost = fields.Float(
|
||||
string='Unit Cost', readonly=True,
|
||||
digits=dp.get_precision('Product Price'),
|
||||
help="This cost per unit in the unit of measure of the product "
|
||||
"in company currency takes into account "
|
||||
"the cost of the raw materials and the labour cost defined on"
|
||||
"the BOM.")
|
||||
|
||||
company_currency_id = fields.Many2one(
|
||||
related='company_id.currency_id', readonly=True,
|
||||
string='Company Currency')
|
||||
|
||||
def compute_order_unit_cost(self):
|
||||
self.ensure_one()
|
||||
mo_total_price = 0.0 # In the UoM of the M0
|
||||
labor_cost_per_unit = 0.0 # In the UoM of the product
|
||||
extra_cost_per_unit = 0.0 # In the UoM of the product
|
||||
# I read the raw materials MO, not on BOM, in order to make
|
||||
# it work with the "dynamic" BOMs (few raw material are auto-added
|
||||
# on the fly on MO)
|
||||
prec = self.env['decimal.precision'].precision_get(
|
||||
'Product Unit of Measure')
|
||||
for raw_smove in self.move_raw_ids:
|
||||
# I don't filter on state, in order to make it work with
|
||||
# partial productions
|
||||
# For partial productions, mo.product_qty is not updated
|
||||
# so we compute with fully qty and we compute with all raw
|
||||
# materials (consumed or not), so it gives a good price
|
||||
# per unit at the end
|
||||
raw_price = raw_smove.product_id.standard_price
|
||||
raw_material_cost = raw_price * raw_smove.product_qty
|
||||
logger.info(
|
||||
'MO %s product %s: raw_material_cost=%s',
|
||||
self.name, raw_smove.product_id.display_name,
|
||||
raw_material_cost)
|
||||
mo_total_price += raw_material_cost
|
||||
if self.bom_id:
|
||||
bom = self.bom_id
|
||||
# if not bom.total_labour_cost:
|
||||
# raise orm.except_orm(
|
||||
# _('Error:'),
|
||||
# _("Total Labor Cost is 0 on bill of material '%s'.")
|
||||
# % bom.name)
|
||||
if float_is_zero(bom.product_qty, precision_digits=prec):
|
||||
raise UserError(_(
|
||||
"Missing Product Quantity on bill of material '%s'.")
|
||||
% bom.display_name)
|
||||
bom_qty_product_uom = bom.product_uom_id._compute_quantity(
|
||||
bom.product_qty, bom.product_tmpl_id.uom_id)
|
||||
assert bom_qty_product_uom > 0, 'BoM qty should be positive'
|
||||
labor_cost_per_unit = bom.total_labour_cost / bom_qty_product_uom
|
||||
extra_cost_per_unit = bom.extra_cost / bom_qty_product_uom
|
||||
# mo_standard_price and labor_cost_per_unit are
|
||||
# in the UoM of the product (not of the MO/BOM)
|
||||
mo_qty_product_uom = self.product_uom_id._compute_quantity(
|
||||
self.product_qty, self.product_id.uom_id)
|
||||
assert mo_qty_product_uom > 0, 'MO qty should be positive'
|
||||
mo_standard_price = mo_total_price / mo_qty_product_uom
|
||||
logger.info(
|
||||
'MO %s: labor_cost_per_unit=%s extra_cost_per_unit=%s',
|
||||
self.name, labor_cost_per_unit, extra_cost_per_unit)
|
||||
mo_standard_price += labor_cost_per_unit
|
||||
mo_standard_price += extra_cost_per_unit
|
||||
return mo_standard_price
|
||||
|
||||
def post_inventory(self):
|
||||
'''This is the method where _action_done() is called on finished move
|
||||
So we write on 'price_unit' of the finished move and THEN we call
|
||||
super() which will call _action_done() which itself calls
|
||||
product_price_update_before_done()'''
|
||||
for order in self:
|
||||
if order.product_id.cost_method == 'average':
|
||||
unit_cost = order.compute_order_unit_cost()
|
||||
order.unit_cost = unit_cost
|
||||
logger.info('MO %s: unit_cost=%s', order.name, unit_cost)
|
||||
for finished_move in order.move_finished_ids.filtered(
|
||||
lambda x: x.product_id == order.product_id):
|
||||
finished_move.price_unit = unit_cost
|
||||
return super(MrpProduction, self).post_inventory()
|
||||
288
mrp_average_cost/mrp.py
Normal file
288
mrp_average_cost/mrp.py
Normal file
@@ -0,0 +1,288 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (C) 2016-2019 Akretion (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models, fields, api, _
|
||||
import odoo.addons.decimal_precision as dp
|
||||
from odoo.tools import float_compare, float_is_zero
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MrpBomLabourLine(models.Model):
|
||||
_name = 'mrp.bom.labour.line'
|
||||
_description = 'Labour lines on BOM'
|
||||
|
||||
bom_id = fields.Many2one(
|
||||
'mrp.bom', string='Labour Lines', ondelete='cascade')
|
||||
labour_time = fields.Float(
|
||||
string='Labour Time', required=True,
|
||||
digits=dp.get_precision('Labour Hours'),
|
||||
help="Average labour time for the production of "
|
||||
"items of the BOM, in hours.")
|
||||
labour_cost_profile_id = fields.Many2one(
|
||||
'labour.cost.profile', string='Labour Cost Profile', required=True)
|
||||
note = fields.Text(string='Note')
|
||||
|
||||
_sql_constraints = [(
|
||||
'labour_time_positive',
|
||||
'CHECK (labour_time >= 0)',
|
||||
"The value of the field 'Labour Time' must be positive or 0.")]
|
||||
|
||||
|
||||
class MrpBom(models.Model):
|
||||
_inherit = 'mrp.bom'
|
||||
|
||||
@api.depends('labour_line_ids.labour_time', 'labour_line_ids.labour_cost_profile_id.hour_cost')
|
||||
def _compute_total_labour_cost(self):
|
||||
for bom in self:
|
||||
cost = 0.0
|
||||
for lline in bom.labour_line_ids:
|
||||
cost += lline.labour_time * lline.labour_cost_profile_id.hour_cost
|
||||
bom.total_labour_cost = cost
|
||||
|
||||
@api.depends('bom_line_ids.product_id.standard_price', 'total_labour_cost', 'extra_cost')
|
||||
def _compute_total_cost(self):
|
||||
puo = self.pool['product.uom']
|
||||
for bom in self:
|
||||
component_cost = 0.0
|
||||
for line in bom.bom_line_ids:
|
||||
component_price = line.product_id.standard_price
|
||||
component_qty_product_uom = puo._compute_qty_obj(
|
||||
cr, uid, line.product_uom, line.product_qty,
|
||||
line.product_id.uom_id, context=context) # TODO
|
||||
component_cost += component_price * component_qty_product_uom
|
||||
total_cost = component_cost + bom.extra_cost + bom.total_labour_cost
|
||||
bom.total_components_cost = component_cost
|
||||
bom.total_cost = total_cost
|
||||
|
||||
labour_line_ids = fields.One2many(
|
||||
'mrp.bom.labour.line', 'bom_id', string='Labour Lines')
|
||||
total_labour_cost = fields.Float(
|
||||
compute='_compute_total_labour_cost', readonly=True,
|
||||
digits=dp.get_precision('Product Price'),
|
||||
string="Total Labour Cost", store=True)
|
||||
extra_cost = fields.Float(
|
||||
string='Extra Cost', track_visibility='onchange',
|
||||
digits=dp.get_precision('Product Price'),
|
||||
help="Extra cost for the production of the quantity of "
|
||||
"items of the BOM, in company currency. "
|
||||
"You can use this field to enter the cost of the consumables "
|
||||
"that are used to produce the product but are not listed in "
|
||||
"the BOM")
|
||||
total_components_cost = fields.Float(
|
||||
compute='_compute_total_cost', readonly=True,
|
||||
digits=dp.get_precision('Product Price'),
|
||||
string='Total Components Cost')
|
||||
total_cost = fields.Float(
|
||||
compute='_compute_total_cost', readonly=True,
|
||||
string='Total Cost',
|
||||
digits=dp.get_precision('Product Price'),
|
||||
help="Total Cost = Total Components Cost + "
|
||||
"Total Labour Cost + Extra Cost")
|
||||
company_currency_id = fields.Many2one(
|
||||
related='company_id.currency_id', readonly=True,
|
||||
string='Company Currency')
|
||||
# to display in bom lines
|
||||
|
||||
class MrpBomLine(models.Model):
|
||||
_inherit = 'mrp.bom.line'
|
||||
|
||||
standard_price = fields.Float(
|
||||
related='product_id.standard_price', readonly=True,
|
||||
string='Standard Price')
|
||||
|
||||
def manual_update_product_standard_price(self, cr, uid, ids, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
ctx = context.copy()
|
||||
if 'product_price_history_origin' not in ctx:
|
||||
ctx['product_price_history_origin'] = u'Manual update from BOM'
|
||||
precision = self.pool['decimal.precision'].precision_get(
|
||||
cr, uid, 'Product Price')
|
||||
for bom in self.browse(cr, uid, ids, context=context):
|
||||
if not bom.product_id:
|
||||
continue
|
||||
if float_compare(
|
||||
bom.product_id.standard_price, bom.total_cost,
|
||||
precision_digits=precision):
|
||||
bom.product_id.write(
|
||||
{'standard_price': bom.total_cost}, context=ctx)
|
||||
logger.info(
|
||||
'Cost price updated to %s on product %s',
|
||||
bom.total_cost, bom.product_id.name_get()[0][1])
|
||||
return True
|
||||
|
||||
def _phantom_update_product_standard_price(self, cr, uid, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
ctx = context.copy()
|
||||
ctx['product_price_history_origin'] = 'Automatic update of Phantom BOMs'
|
||||
mbo = self.pool['mrp.bom']
|
||||
bom_ids = mbo.search(
|
||||
cr, uid, [('type', '=', 'phantom')], context=context)
|
||||
self.manual_update_product_standard_price(
|
||||
cr, uid, bom_ids, context=ctx)
|
||||
return True
|
||||
|
||||
|
||||
class LabourCostProfile(models.Model):
|
||||
_name = 'labour.cost.profile'
|
||||
_inherit = ['mail.thread']
|
||||
_description = 'Labour Cost Profile'
|
||||
|
||||
name = fields.Char(
|
||||
string='Name', required=True, track_visibility='onchange')
|
||||
hour_cost = fields.Float(
|
||||
string='Cost per Hour', required=True,
|
||||
digits=dp.get_precision('Product Price'),
|
||||
track_visibility='onchange',
|
||||
help="Labour cost per hour per person in company currency")
|
||||
company_id = fields.Many2one(
|
||||
'res.company', string='Company', required=True,
|
||||
default=lambda self: self.env['res.company']._company_default_get())
|
||||
company_currency_id = fields.Many2one(
|
||||
related='company_id.currency_id', readonly=True, store=True,
|
||||
string='Company Currency')
|
||||
|
||||
@api.depends('name', 'hour_cost', 'company_currency_id.symbol')
|
||||
def name_get(self):
|
||||
res = []
|
||||
for record in self:
|
||||
res.append((record.id, u'%s (%s %s)' % (
|
||||
record.name, record.hour_cost,
|
||||
record.company_currency_id.symbol)))
|
||||
return res
|
||||
|
||||
|
||||
class MrpProduction(models.Model):
|
||||
_inherit = 'mrp.production'
|
||||
|
||||
unit_cost = fields.Float(
|
||||
string='Unit Cost', readonly=True,
|
||||
digits=dp.get_precision('Product Price'),
|
||||
help="This cost per unit in the unit of measure of the product "
|
||||
"in company currency takes into account "
|
||||
"the cost of the raw materials and the labour cost defined on"
|
||||
"the BOM.")
|
||||
company_currency_id = fields.Many2one(
|
||||
related='company_id.currency_id', readonly=True,
|
||||
string='Company Currency')
|
||||
|
||||
# TODO port to v12
|
||||
def compute_order_unit_cost(self, cr, uid, order, context=None):
|
||||
puo = self.pool['product.uom']
|
||||
mo_total_price = 0.0 # In the UoM of the M0
|
||||
labor_cost_per_unit = 0.0 # In the UoM of the product
|
||||
extra_cost_per_unit = 0.0 # In the UoM of the product
|
||||
# I read the raw materials MO, not on BOM, in order to make
|
||||
# it work with the "dynamic" BOMs (few raw material are auto-added
|
||||
# on the fly on MO)
|
||||
for raw_smove in order.move_lines + order.move_lines2:
|
||||
# I don't filter on state, in order to make it work with
|
||||
# partial productions
|
||||
# For partial productions, mo.product_qty is not updated
|
||||
# so we compute with fully qty and we compute with all raw
|
||||
# materials (consumed or not), so it gives a good price
|
||||
# per unit at the end
|
||||
raw_price = raw_smove.product_id.standard_price
|
||||
raw_qty_product_uom = puo._compute_qty_obj(
|
||||
cr, uid, raw_smove.product_uom, raw_smove.product_qty,
|
||||
raw_smove.product_id.uom_id, context=context)
|
||||
raw_material_cost = raw_price * raw_qty_product_uom
|
||||
logger.info(
|
||||
'MO %s product %s: raw_material_cost=%s',
|
||||
order.name, raw_smove.product_id.name, raw_material_cost)
|
||||
mo_total_price += raw_material_cost
|
||||
if order.bom_id:
|
||||
bom = order.bom_id
|
||||
#if not bom.total_labour_cost:
|
||||
# raise orm.except_orm(
|
||||
# _('Error:'),
|
||||
# _("Total Labor Cost is 0 on bill of material '%s'.")
|
||||
# % bom.name)
|
||||
if not bom.product_qty:
|
||||
raise orm.except_orm(
|
||||
_('Error:'),
|
||||
_("Missing Product Quantity on bill of material '%s'.")
|
||||
% bom.name)
|
||||
bom_qty_product_uom = puo._compute_qty_obj(
|
||||
cr, uid, bom.product_uom, bom.product_qty,
|
||||
bom.product_id.uom_id, context=context)
|
||||
assert bom_qty_product_uom > 0, 'BoM qty should be positive'
|
||||
labor_cost_per_unit = bom.total_labour_cost / bom_qty_product_uom
|
||||
extra_cost_per_unit = bom.extra_cost / bom_qty_product_uom
|
||||
# mo_standard_price and labor_cost_per_unit are
|
||||
# in the UoM of the product (not of the MO/BOM)
|
||||
mo_qty_product_uom = puo._compute_qty_obj(
|
||||
cr, uid, order.product_uom, order.product_qty,
|
||||
order.product_id.uom_id, context=context)
|
||||
assert mo_qty_product_uom > 0, 'MO qty should be positive'
|
||||
mo_standard_price = mo_total_price / mo_qty_product_uom
|
||||
logger.info(
|
||||
'MO %s: labor_cost_per_unit=%s', order.name, labor_cost_per_unit)
|
||||
logger.info(
|
||||
'MO %s: extra_cost_per_unit=%s', order.name, extra_cost_per_unit)
|
||||
mo_standard_price += labor_cost_per_unit
|
||||
mo_standard_price += extra_cost_per_unit
|
||||
order.write({'unit_cost': mo_standard_price}, context=context)
|
||||
logger.info(
|
||||
'MO %s: unit_cost=%s', order.name, mo_standard_price)
|
||||
return mo_standard_price
|
||||
|
||||
def update_standard_price(self, cr, uid, order, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
puo = self.pool['product.uom']
|
||||
product = order.product_id
|
||||
mo_standard_price = self.compute_order_unit_cost(
|
||||
cr, uid, order, context=context)
|
||||
mo_qty_product_uom = puo._compute_qty_obj(
|
||||
cr, uid, order.product_uom, order.product_qty,
|
||||
order.product_id.uom_id, context=context)
|
||||
# I can't use the native method _update_average_price of stock.move
|
||||
# because it only works on move.picking_id.type == 'in'
|
||||
# As we do the super() at the END of this method,
|
||||
# the qty produced by this MO in NOT counted inside
|
||||
# product.qty_available
|
||||
qty_before_mo = product.qty_available
|
||||
logger.info(
|
||||
'MO %s product %s: standard_price before production: %s',
|
||||
order.name, product.name, product.standard_price)
|
||||
logger.info(
|
||||
'MO %s product %s: qty before production: %s',
|
||||
order.name, product.name, qty_before_mo)
|
||||
# Here, we handle as if we were in v8 (!)
|
||||
# so we consider that standard_price is in company currency
|
||||
# It will not work if you are in multi-company environment
|
||||
# with companies in different currencies
|
||||
if not qty_before_mo + mo_qty_product_uom:
|
||||
new_std_price = mo_standard_price
|
||||
else:
|
||||
new_std_price = (
|
||||
(product.standard_price * qty_before_mo) +
|
||||
(mo_standard_price * mo_qty_product_uom)) / \
|
||||
(qty_before_mo + mo_qty_product_uom)
|
||||
ctx_product = context.copy()
|
||||
ctx_product['product_price_history_origin'] = _(
|
||||
'%s (Qty before: %s - Added qty: %s - Unit price of '
|
||||
'added qty: %s)') % (
|
||||
order.name, qty_before_mo, mo_qty_product_uom, mo_standard_price)
|
||||
product.write({'standard_price': new_std_price}, context=ctx_product)
|
||||
logger.info(
|
||||
'MO %s product %s: standard_price updated to %s',
|
||||
order.name, product.name, new_std_price)
|
||||
return True
|
||||
|
||||
def action_produce(
|
||||
self, cr, uid, production_id, production_qty, production_mode,
|
||||
context=None):
|
||||
if production_mode == 'consume_produce':
|
||||
order = self.browse(cr, uid, production_id, context=context)
|
||||
if order.product_id.cost_method == 'average':
|
||||
self.update_standard_price(cr, uid, order, context=context)
|
||||
return super(MrpProduction, self).action_produce(
|
||||
cr, uid, production_id, production_qty, production_mode,
|
||||
context=context)
|
||||
@@ -16,7 +16,6 @@
|
||||
<field name="numbercall">-1</field> <!-- don't limit the number of calls -->
|
||||
<field name="doall" eval="False"/>
|
||||
<field name="model_id" ref="mrp.model_mrp_bom"/>
|
||||
<field name="state">code</field>
|
||||
<field name="code">model._phantom_update_product_standard_price()</field>
|
||||
</record>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# Copyright 2016-2019 Akretion France (http://www.akretion.com/)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# © 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2016-2019 Akretion France (http://www.akretion.com/)
|
||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
© 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
# © 2019 Akretion (http://www.akretion.com)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
|
||||
{
|
||||
'name': 'MRP Product Tree Default',
|
||||
'version': '12.0.1.0.0',
|
||||
'category': 'Product',
|
||||
'license': 'AGPL-3',
|
||||
'summary': 'Tree view by default instead of kanban for Products',
|
||||
'description': """
|
||||
Replace default kanban view by tree view for product menu in MRP
|
||||
main menu
|
||||
""",
|
||||
'author': 'Akretion',
|
||||
'website': 'http://www.akretion.com',
|
||||
'depends': ['mrp'],
|
||||
'data': [
|
||||
'views/product_template.xml'
|
||||
],
|
||||
'installable': True,
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<odoo>
|
||||
|
||||
<record id="mrp.product_template_action" model="ir.actions.act_window">
|
||||
<field name="view_mode">tree,form,kanban</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -1,32 +1,25 @@
|
||||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * mrp_usability
|
||||
# * mrp_usability
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 12.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2019-07-16 13:56+0000\n"
|
||||
"PO-Revision-Date: 2019-07-16 16:01+0200\n"
|
||||
"POT-Creation-Date: 2019-03-26 08:56+0000\n"
|
||||
"PO-Revision-Date: 2019-03-26 08:56+0000\n"
|
||||
"Last-Translator: <>\n"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Content-Transfer-Encoding: \n"
|
||||
"Plural-Forms: \n"
|
||||
"Language: fr\n"
|
||||
"X-Generator: Poedit 2.0.6\n"
|
||||
|
||||
#. module: mrp_usability
|
||||
#: model_terms:ir.ui.view,arch_db:mrp_usability.mrp_production_form_view
|
||||
msgid "Are you sure you want to cancel this manufacturing order?"
|
||||
msgstr "Etes vous sur de vouloir annuler cet ordre de production"
|
||||
|
||||
#. module: mrp_usability
|
||||
#: model_terms:ir.ui.view,arch_db:mrp_usability.report_mrporder
|
||||
msgid "Lot"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_usability
|
||||
#: model_terms:ir.ui.view,arch_db:mrp_usability.report_mrporder
|
||||
msgid "Product"
|
||||
@@ -44,14 +37,11 @@ msgstr "Quantité"
|
||||
|
||||
#. module: mrp_usability
|
||||
#: model_terms:ir.ui.view,arch_db:mrp_usability.report_mrporder
|
||||
msgid ""
|
||||
"These products were unavailable (or partially) while edition of this Manufacturing Order.\n"
|
||||
" Here is complete quantities for these."
|
||||
msgstr ""
|
||||
"Les produits ci-dessous étaient indisponibles (complètement ou partiellement) lors de l'édition de l'OF.<br/>\n"
|
||||
"Voici les quantités totales de ceux-ci."
|
||||
msgid "These products were unavailable while edition of this Manufacturing Order"
|
||||
msgstr "Ces produits étaient indisponibles au moment de l'édition de l'Ordre de Production"
|
||||
|
||||
#. module: mrp_usability
|
||||
#: model_terms:ir.ui.view,arch_db:mrp_usability.view_mrp_bom_filter
|
||||
msgid "Type"
|
||||
msgstr ""
|
||||
msgstr "Type"
|
||||
|
||||
|
||||
@@ -11,12 +11,11 @@
|
||||
<td t-if="has_serial_number"><span t-field="ml.lot_id"/></td>
|
||||
</xpath>
|
||||
|
||||
<xpath expr="//div[hasclass('oe_structure')][2]" position="after">
|
||||
<xpath expr="//div[@class='oe_structure'][2]" position="after">
|
||||
<t t-set="has_product_unavailable"
|
||||
t-value="any(o.move_raw_ids.filtered(lambda x: x.product_uom_qty > x.reserved_availability))"/>
|
||||
t-value="any(o.move_raw_ids.filtered(lambda x: not x.reserved_availability))"/>
|
||||
<h4 if="has_product_unavailable">
|
||||
These products were unavailable (or partially) while edition of this Manufacturing Order.
|
||||
Here is complete quantities for these.
|
||||
These products were unavailable while edition of this Manufacturing Order
|
||||
</h4>
|
||||
<table class="table table-sm" t-if="o.move_raw_ids and has_product_unavailable">
|
||||
<thead>
|
||||
@@ -27,7 +26,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<t t-set="lines"
|
||||
t-value="o.move_raw_ids.filtered(lambda x: x.product_uom_qty > x.reserved_availability)"/>
|
||||
t-value="o.move_raw_ids.filtered(lambda x: not x.reserved_availability)"/>
|
||||
<t t-foreach="lines" t-as="ml">
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import models
|
||||
from . import product
|
||||
from . import pricelist
|
||||
|
||||
@@ -28,11 +28,7 @@ This module has been written by Alexis de Lattre from Akretion <alexis.delattre@
|
||||
'depends': ['product'],
|
||||
'data': [
|
||||
'security/product_security.xml',
|
||||
'views/product_supplierinfo_view.xml',
|
||||
'views/product_price_history_view.xml',
|
||||
'views/product_pricelist_view.xml',
|
||||
'views/product_template_view.xml',
|
||||
'views/product_view.xml',
|
||||
],
|
||||
'product_view.xml',
|
||||
],
|
||||
'installable': True,
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import product
|
||||
from . import product_template
|
||||
from . import product_supplierinfo
|
||||
from . import product_price_history
|
||||
from . import pricelist
|
||||
@@ -1,48 +0,0 @@
|
||||
# © 2015-2016 Akretion (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# @author Raphaël Valyi <rvalyi@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models, fields
|
||||
from odoo.tools.safe_eval import safe_eval
|
||||
|
||||
|
||||
class ProductProduct(models.Model):
|
||||
_inherit = 'product.product'
|
||||
|
||||
default_code = fields.Char(
|
||||
track_visibility='onchange',
|
||||
copy=False)
|
||||
|
||||
barcode = fields.Char(
|
||||
track_visibility='onchange',
|
||||
copy=False)
|
||||
|
||||
weight = fields.Float(
|
||||
track_visibility='onchange')
|
||||
|
||||
active = fields.Boolean(
|
||||
track_visibility='onchange')
|
||||
|
||||
price_history_ids = fields.One2many(
|
||||
comodel_name='product.price.history',
|
||||
inverse_name='product_id',
|
||||
string='Product Price History')
|
||||
|
||||
_sql_constraints = [(
|
||||
# Maybe it could be better to have a constrain per company
|
||||
# but the company_id field is on product.template,
|
||||
# not on product.product
|
||||
# If it's a problem, we'll create a company_id field on
|
||||
# product.product
|
||||
'default_code_uniq',
|
||||
'unique(default_code)',
|
||||
'This internal reference already exists!')]
|
||||
|
||||
def show_product_price_history(self):
|
||||
self.ensure_one()
|
||||
action = self.env.ref(
|
||||
'product_usability.product_price_history_action').read()[0]
|
||||
action['domain'] = safe_eval(action['domain'])
|
||||
action['domain'].append(('product_id', '=', self.id))
|
||||
return action
|
||||
@@ -1,16 +0,0 @@
|
||||
# © 2015-2016 Akretion (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# @author Raphaël Valyi <rvalyi@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models, fields
|
||||
|
||||
|
||||
class ProductPriceHistory(models.Model):
|
||||
_inherit = 'product.price.history'
|
||||
|
||||
company_currency_id = fields.Many2one(
|
||||
related='company_id.currency_id',
|
||||
readonly=True,
|
||||
compute_sudo=True,
|
||||
string='Company Currency')
|
||||
@@ -1,13 +0,0 @@
|
||||
# © 2015-2016 Akretion (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# @author Raphaël Valyi <rvalyi@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models, fields
|
||||
|
||||
|
||||
class ProductSupplierinfo(models.Model):
|
||||
_inherit = 'product.supplierinfo'
|
||||
|
||||
name = fields.Many2one(
|
||||
domain=[('supplier', '=', True), ('parent_id', '=', False)])
|
||||
@@ -1,40 +0,0 @@
|
||||
# © 2015-2016 Akretion (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# @author Raphaël Valyi <rvalyi@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models, fields
|
||||
|
||||
|
||||
class ProductTemplate(models.Model):
|
||||
_inherit = 'product.template'
|
||||
|
||||
name = fields.Char(
|
||||
track_visibility='onchange')
|
||||
|
||||
type = fields.Selection(
|
||||
track_visibility='onchange')
|
||||
|
||||
categ_id = fields.Many2one(
|
||||
track_visibility='onchange')
|
||||
|
||||
list_price = fields.Float(
|
||||
track_visibility='onchange')
|
||||
|
||||
sale_ok = fields.Boolean(
|
||||
track_visibility='onchange')
|
||||
|
||||
purchase_ok = fields.Boolean(
|
||||
track_visibility='onchange')
|
||||
|
||||
active = fields.Boolean(
|
||||
track_visibility='onchange')
|
||||
|
||||
def show_product_price_history(self):
|
||||
self.ensure_one()
|
||||
products = self.env['product.product'].search(
|
||||
[('product_tmpl_id', '=', self._context['active_id'])])
|
||||
action = self.env.ref(
|
||||
'product_usability.product_price_history_action').read()[0]
|
||||
action['domain'] = [('product_id', 'in', products.ids)]
|
||||
return action
|
||||
73
product_usability/product.py
Normal file
73
product_usability/product.py
Normal file
@@ -0,0 +1,73 @@
|
||||
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models, fields
|
||||
|
||||
|
||||
class ProductTemplate(models.Model):
|
||||
_inherit = 'product.template'
|
||||
|
||||
name = fields.Char(track_visibility='onchange')
|
||||
type = fields.Selection(track_visibility='onchange')
|
||||
categ_id = fields.Many2one(track_visibility='onchange')
|
||||
list_price = fields.Float(track_visibility='onchange')
|
||||
sale_ok = fields.Boolean(track_visibility='onchange')
|
||||
purchase_ok = fields.Boolean(track_visibility='onchange')
|
||||
active = fields.Boolean(track_visibility='onchange')
|
||||
|
||||
def show_product_price_history(self):
|
||||
self.ensure_one()
|
||||
products = self.env['product.product'].search(
|
||||
[('product_tmpl_id', '=', self._context['active_id'])])
|
||||
action = self.env['ir.actions.act_window'].for_xml_id(
|
||||
'product_usability', 'product_price_history_action')
|
||||
action.update({
|
||||
'domain': "[('id', 'in', %s)]" % products.ids,
|
||||
})
|
||||
return action
|
||||
|
||||
|
||||
class ProductProduct(models.Model):
|
||||
_inherit = 'product.product'
|
||||
|
||||
default_code = fields.Char(track_visibility='onchange', copy=False)
|
||||
barcode = fields.Char(track_visibility='onchange', copy=False)
|
||||
weight = fields.Float(track_visibility='onchange')
|
||||
active = fields.Boolean(track_visibility='onchange')
|
||||
price_history_ids = fields.One2many(
|
||||
'product.price.history', 'product_id',
|
||||
string='Product Price History')
|
||||
|
||||
_sql_constraints = [(
|
||||
# Maybe it could be better to have a constrain per company
|
||||
# but the company_id field is on product.template,
|
||||
# not on product.product
|
||||
# If it's a problem, we'll create a company_id field on
|
||||
# product.product
|
||||
'default_code_uniq',
|
||||
'unique(default_code)',
|
||||
'This internal reference already exists!')]
|
||||
|
||||
def show_product_price_history(self):
|
||||
self.ensure_one()
|
||||
action = self.env['ir.actions.act_window'].for_xml_id(
|
||||
'product_usability', 'product_price_history_action')
|
||||
action.update({
|
||||
'domain': "[('product_id', '=', %d)]" % self.ids[0],
|
||||
})
|
||||
return action
|
||||
|
||||
|
||||
class ProductSupplierinfo(models.Model):
|
||||
_inherit = 'product.supplierinfo'
|
||||
|
||||
name = fields.Many2one(
|
||||
domain=[('supplier', '=', True), ('parent_id', '=', False)])
|
||||
|
||||
|
||||
class ProductPriceHistory(models.Model):
|
||||
_inherit = 'product.price.history'
|
||||
|
||||
company_currency_id = fields.Many2one(
|
||||
related='company_id.currency_id', readonly=True, compute_sudo=True,
|
||||
string='Company Currency')
|
||||
223
product_usability/product_view.xml
Normal file
223
product_usability/product_view.xml
Normal file
@@ -0,0 +1,223 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
© 2015-2016 Akretion (http://www.akretion.com/)
|
||||
@author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
<odoo>
|
||||
|
||||
|
||||
<!-- product.price.history -->
|
||||
<record id="product_price_history_form" model="ir.ui.view">
|
||||
<field name="name">product.price.history.form</field>
|
||||
<field name="model">product.price.history</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Product Price History">
|
||||
<group name="main">
|
||||
<field name="product_id" invisible="not context.get('product_price_history_main_view')"/>
|
||||
<field name="datetime"/>
|
||||
<field name="cost" widget="monetary" options="{'currency_field': 'company_currency_id'}"/>
|
||||
<field name="create_uid"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
<field name="company_currency_id" invisible="1"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="product_price_history_tree" model="ir.ui.view">
|
||||
<field name="name">product.price.history.tree</field>
|
||||
<field name="model">product.price.history</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Product Price History" editable="bottom">
|
||||
<field name="product_id" invisible="not context.get('product_price_history_main_view')"/>
|
||||
<field name="datetime"/>
|
||||
<field name="cost" widget="monetary" options="{'currency_field': 'company_currency_id'}"/>
|
||||
<field name="create_uid"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
<field name="company_currency_id" invisible="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="product_price_history_search" model="ir.ui.view">
|
||||
<field name="name">product.price.history.search</field>
|
||||
<field name="model">product.price.history</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Search Product Price History">
|
||||
<field name="product_id"/>
|
||||
<group string="Group By" name="groupby">
|
||||
<filter name="product_groupby" string="Product" context="{'group_by': 'product_id'}"/>
|
||||
<filter name="datetime_groupby" string="Date" context="{'group_by': 'datetime:month'}"/>
|
||||
<filter name="create_uid_groupby" string="Created by" context="{'group_by': 'create_uid'}"/>
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="product_price_history_action" model="ir.actions.act_window">
|
||||
<field name="name">Product Price History</field>
|
||||
<field name="res_model">product.price.history</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="context">{'product_price_history_main_view': True}</field>
|
||||
</record>
|
||||
|
||||
<!--
|
||||
<menuitem id="product_price_history_menu" action="product_price_history_action"
|
||||
parent="product.prod_config_main" sequence="55"/> -->
|
||||
|
||||
<!-- product.template -->
|
||||
<record id="product_template_form_view" model="ir.ui.view">
|
||||
<field name="name">usability.product.template.form</field>
|
||||
<field name="model">product.template</field>
|
||||
<field name="inherit_id" ref="product.product_template_form_view" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="standard_price" class="oe_inline" position="after">
|
||||
<button name="show_product_price_history" class="oe_inline oe_link" type="object" string="Show History" context="{'active_id': active_id}"/>
|
||||
</field>
|
||||
<!-- Don't make it too big, othesize computers with small resolutions
|
||||
will see the product name + image under the block of buttons -->
|
||||
<div class="oe_title" position="attributes">
|
||||
<attribute name="style">width: 650px;</attribute>
|
||||
</div>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- It also adds on product.product search view -->
|
||||
<record id="product_template_search_view" model="ir.ui.view">
|
||||
<field name="name">usability.product.template.search</field>
|
||||
<field name="model">product.template</field>
|
||||
<field name="inherit_id" ref="product.product_template_search_view" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="categ_id" position="after">
|
||||
<field name="seller_ids" string="Supplier" filter_domain="[('seller_ids.name', 'ilike', self)]"/>
|
||||
</field>
|
||||
<field name="pricelist_id" position="after">
|
||||
<group string="Group By" name="groupby">
|
||||
<filter name="categ_groupby" string="Internal Category" context="{'group_by': 'categ_id'}"/>
|
||||
<filter name="type_groupby" string="Type" context="{'group_by': 'type'}"/>
|
||||
</group>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="product_template_tree_view" model="ir.ui.view">
|
||||
<field name="name">usability.product.template.tree</field>
|
||||
<field name="model">product.template</field>
|
||||
<field name="inherit_id" ref="product.product_template_tree_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="list_price" position="after">
|
||||
<field name="currency_id" invisible="1"/>
|
||||
</field>
|
||||
<field name="list_price" position="attributes">
|
||||
<attribute name="widget">monetary</attribute>
|
||||
</field>
|
||||
<field name="standard_price" position="attributes">
|
||||
<attribute name="widget">monetary</attribute>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<!-- product.product -->
|
||||
<record id="product_product_tree_view" model="ir.ui.view">
|
||||
<field name="name">usability.product.product.tree</field>
|
||||
<field name="model">product.product</field>
|
||||
<field name="inherit_id" ref="product.product_product_tree_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="lst_price" position="after">
|
||||
<field name="currency_id" invisible="1"/>
|
||||
</field>
|
||||
<field name="lst_price" position="attributes">
|
||||
<attribute name="widget">monetary</attribute>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- product.pricelist -->
|
||||
<record id="product_pricelist_view_tree" model="ir.ui.view">
|
||||
<field name="name">usability.product.pricelist.tree</field>
|
||||
<field name="model">product.pricelist</field>
|
||||
<field name="inherit_id" ref="product.product_pricelist_view_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="currency_id" position="after">
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- product.pricelist.item -->
|
||||
<record id="product_pricelist_item_search" model="ir.ui.view">
|
||||
<field name="name">usability.product.pricelist.item.search</field>
|
||||
<field name="model">product.pricelist.item</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Search Pricelist Items">
|
||||
<field name="pricelist_id"/>
|
||||
<field name="product_tmpl_id"/>
|
||||
<field name="product_id"/>
|
||||
<field name="categ_id"/>
|
||||
<group string="Group By" name="groupby">
|
||||
<filter name="pricelist_groupby" string="Pricelist" context="{'group_by': 'pricelist_id'}"/>
|
||||
<filter name="applied_on_groupby" string="Apply On" context="{'group_by': 'applied_on'}"/>
|
||||
<filter name="base_on_groupby" string="Based On" context="{'group_by': 'base'}"/>
|
||||
<filter name="compute_price_groupby" string="Compute Price" context="{'group_by': 'compute_price'}"/>
|
||||
<filter name="currency_groupby" string="Currency" context="{'group_by': 'currency_id'}"/>
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="product_pricelist_item_form_view" model="ir.ui.view">
|
||||
<field name="name">usability.product.pricelist.item.form</field>
|
||||
<field name="model">product.pricelist.item</field>
|
||||
<field name="inherit_id" ref="product.product_pricelist_item_form_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="applied_on" position="before">
|
||||
<field name="pricelist_id" invisible="not context.get('product_pricelist_item_main_view')"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
|
||||
<record id="product_pricelist_item_tree_view" model="ir.ui.view">
|
||||
<field name="name">usability.product.pricelist.item.tree</field>
|
||||
<field name="model">product.pricelist.item</field>
|
||||
<field name="inherit_id" ref="product.product_pricelist_item_tree_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="name" position="before">
|
||||
<field name="pricelist_id" invisible="not context.get('product_pricelist_item_main_view')"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- product.supplierinfo -->
|
||||
<record id="product_supplierinfo_tree_view" model="ir.ui.view">
|
||||
<field name="model">product.supplierinfo</field>
|
||||
<field name="inherit_id" ref="product.product_supplierinfo_tree_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="product_tmpl_id" position="after">
|
||||
<field name="product_name"/>
|
||||
<field name="product_code" string="Supplier Code"/>
|
||||
</field>
|
||||
<field name="price" position="after">
|
||||
<field name="currency_id" groups="base.group_multi_currency"/>
|
||||
</field>
|
||||
<field name="min_qty" position="after">
|
||||
<field name="product_uom" groups="uom.group_uom"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="product_supplierinfo_search_view" model="ir.ui.view">
|
||||
<field name="model">product.supplierinfo</field>
|
||||
<field name="inherit_id" ref="product.product_supplierinfo_search_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="product_tmpl_id" position="after">
|
||||
<field name="product_code" string="Product Supplier Code"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -1,65 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
© 2015-2016 Akretion (http://www.akretion.com/)
|
||||
@author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
<odoo>
|
||||
|
||||
<!-- product.price.history -->
|
||||
<record id="product_price_history_form" model="ir.ui.view">
|
||||
<field name="name">product.price.history.form</field>
|
||||
<field name="model">product.price.history</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Product Price History">
|
||||
<group name="main">
|
||||
<field name="product_id" invisible="not context.get('product_price_history_main_view')"/>
|
||||
<field name="datetime"/>
|
||||
<field name="cost" widget="monetary" options="{'currency_field': 'company_currency_id'}"/>
|
||||
<field name="create_uid"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
<field name="company_currency_id" invisible="1"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="product_price_history_tree" model="ir.ui.view">
|
||||
<field name="name">product.price.history.tree</field>
|
||||
<field name="model">product.price.history</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Product Price History" editable="bottom">
|
||||
<field name="product_id" invisible="not context.get('product_price_history_main_view')"/>
|
||||
<field name="datetime"/>
|
||||
<field name="cost" widget="monetary" options="{'currency_field': 'company_currency_id'}"/>
|
||||
<field name="create_uid"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
<field name="company_currency_id" invisible="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="product_price_history_search" model="ir.ui.view">
|
||||
<field name="name">product.price.history.search</field>
|
||||
<field name="model">product.price.history</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Search Product Price History">
|
||||
<field name="product_id"/>
|
||||
<group string="Group By" name="groupby">
|
||||
<filter name="product_groupby" string="Product" context="{'group_by': 'product_id'}"/>
|
||||
<filter name="datetime_groupby" string="Date" context="{'group_by': 'datetime:month'}"/>
|
||||
<filter name="create_uid_groupby" string="Created by" context="{'group_by': 'create_uid'}"/>
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="product_price_history_action" model="ir.actions.act_window">
|
||||
<field name="name">Product Price History</field>
|
||||
<field name="res_model">product.price.history</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="context">{'product_price_history_main_view': True}</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -1,65 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
© 2015-2016 Akretion (http://www.akretion.com/)
|
||||
@author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
<odoo>
|
||||
|
||||
<!-- product.pricelist -->
|
||||
<record id="product_pricelist_view_tree" model="ir.ui.view">
|
||||
<field name="name">usability.product.pricelist.tree</field>
|
||||
<field name="model">product.pricelist</field>
|
||||
<field name="inherit_id" ref="product.product_pricelist_view_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="currency_id" position="after">
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- product.pricelist.item -->
|
||||
<record id="product_pricelist_item_search" model="ir.ui.view">
|
||||
<field name="name">usability.product.pricelist.item.search</field>
|
||||
<field name="model">product.pricelist.item</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Search Pricelist Items">
|
||||
<field name="pricelist_id"/>
|
||||
<field name="product_tmpl_id"/>
|
||||
<field name="product_id"/>
|
||||
<field name="categ_id"/>
|
||||
<group string="Group By" name="groupby">
|
||||
<filter name="pricelist_groupby" string="Pricelist" context="{'group_by': 'pricelist_id'}"/>
|
||||
<filter name="applied_on_groupby" string="Apply On" context="{'group_by': 'applied_on'}"/>
|
||||
<filter name="base_on_groupby" string="Based On" context="{'group_by': 'base'}"/>
|
||||
<filter name="compute_price_groupby" string="Compute Price" context="{'group_by': 'compute_price'}"/>
|
||||
<filter name="currency_groupby" string="Currency" context="{'group_by': 'currency_id'}"/>
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="product_pricelist_item_form_view" model="ir.ui.view">
|
||||
<field name="name">usability.product.pricelist.item.form</field>
|
||||
<field name="model">product.pricelist.item</field>
|
||||
<field name="inherit_id" ref="product.product_pricelist_item_form_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="applied_on" position="before">
|
||||
<field name="pricelist_id" invisible="not context.get('product_pricelist_item_main_view')"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="product_pricelist_item_tree_view" model="ir.ui.view">
|
||||
<field name="name">usability.product.pricelist.item.tree</field>
|
||||
<field name="model">product.pricelist.item</field>
|
||||
<field name="inherit_id" ref="product.product_pricelist_item_tree_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="name" position="before">
|
||||
<field name="pricelist_id" invisible="not context.get('product_pricelist_item_main_view')"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -1,38 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
© 2015-2016 Akretion (http://www.akretion.com/)
|
||||
@author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
<odoo>
|
||||
|
||||
<!-- product.supplierinfo -->
|
||||
<record id="product_supplierinfo_tree_view" model="ir.ui.view">
|
||||
<field name="model">product.supplierinfo</field>
|
||||
<field name="inherit_id" ref="product.product_supplierinfo_tree_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="product_tmpl_id" position="after">
|
||||
<field name="product_name"/>
|
||||
<field name="product_code" string="Supplier Code"/>
|
||||
</field>
|
||||
<field name="price" position="after">
|
||||
<field name="currency_id" groups="base.group_multi_currency"/>
|
||||
</field>
|
||||
<field name="min_qty" position="after">
|
||||
<field name="product_uom" groups="uom.group_uom"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="product_supplierinfo_search_view" model="ir.ui.view">
|
||||
<field name="model">product.supplierinfo</field>
|
||||
<field name="inherit_id" ref="product.product_supplierinfo_search_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="product_tmpl_id" position="after">
|
||||
<field name="product_code" string="Product Supplier Code"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -1,62 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
© 2015-2016 Akretion (http://www.akretion.com/)
|
||||
@author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
<odoo>
|
||||
|
||||
<!-- product.template -->
|
||||
<record id="product_template_form_view" model="ir.ui.view">
|
||||
<field name="name">usability.product.template.form</field>
|
||||
<field name="model">product.template</field>
|
||||
<field name="inherit_id" ref="product.product_template_form_view" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="standard_price" class="oe_inline" position="after">
|
||||
<button name="show_product_price_history" class="oe_inline oe_link" type="object" string="Show History" context="{'active_id': active_id}"/>
|
||||
</field>
|
||||
<!-- Don't make it too big, othesize computers with small resolutions
|
||||
will see the product name + image under the block of buttons -->
|
||||
<div class="oe_title" position="attributes">
|
||||
<attribute name="style">width: 650px;</attribute>
|
||||
</div>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- It also adds on product.product search view -->
|
||||
<record id="product_template_search_view" model="ir.ui.view">
|
||||
<field name="name">usability.product.template.search</field>
|
||||
<field name="model">product.template</field>
|
||||
<field name="inherit_id" ref="product.product_template_search_view" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="categ_id" position="after">
|
||||
<field name="seller_ids" string="Supplier" filter_domain="[('seller_ids.name', 'ilike', self)]"/>
|
||||
</field>
|
||||
<field name="pricelist_id" position="after">
|
||||
<group string="Group By" name="groupby">
|
||||
<filter name="categ_groupby" string="Internal Category" context="{'group_by': 'categ_id'}"/>
|
||||
<filter name="type_groupby" string="Type" context="{'group_by': 'type'}"/>
|
||||
</group>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="product_template_tree_view" model="ir.ui.view">
|
||||
<field name="name">usability.product.template.tree</field>
|
||||
<field name="model">product.template</field>
|
||||
<field name="inherit_id" ref="product.product_template_tree_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="list_price" position="after">
|
||||
<field name="currency_id" invisible="1"/>
|
||||
</field>
|
||||
<field name="list_price" position="attributes">
|
||||
<attribute name="widget">monetary</attribute>
|
||||
</field>
|
||||
<field name="standard_price" position="attributes">
|
||||
<attribute name="widget">monetary</attribute>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -1,25 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
© 2015-2016 Akretion (http://www.akretion.com/)
|
||||
@author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
<odoo>
|
||||
|
||||
<!-- product.product -->
|
||||
<record id="product_product_tree_view" model="ir.ui.view">
|
||||
<field name="name">usability.product.product.tree</field>
|
||||
<field name="model">product.product</field>
|
||||
<field name="inherit_id" ref="product.product_product_tree_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="lst_price" position="after">
|
||||
<field name="currency_id" invisible="1"/>
|
||||
</field>
|
||||
<field name="lst_price" position="attributes">
|
||||
<attribute name="widget">monetary</attribute>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -1,22 +0,0 @@
|
||||
# © 2019 Akretion (http://www.akretion.com)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
|
||||
{
|
||||
'name': 'Purchase Product Tree Default',
|
||||
'version': '12.0.1.0.0',
|
||||
'category': 'Product',
|
||||
'license': 'AGPL-3',
|
||||
'summary': 'Tree view by default instead of kanban for Products',
|
||||
'description': """
|
||||
Replace default kanban view by tree view for product menu in Purchase
|
||||
main menu
|
||||
""",
|
||||
'author': 'Akretion',
|
||||
'website': 'http://www.akretion.com',
|
||||
'depends': ['purchase'],
|
||||
'data': [
|
||||
'views/product_template.xml'
|
||||
],
|
||||
'installable': True,
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<odoo>
|
||||
|
||||
<record id="purchase.product_normal_action_puchased" model="ir.actions.act_window">
|
||||
<field name="view_mode">tree,form,kanban,activity</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -30,10 +30,6 @@
|
||||
<field name="date_approve" position="after">
|
||||
<field name="origin"/>
|
||||
</field>
|
||||
<!-- Remove once this PR is merged https://github.com/odoo/odoo/pull/35073 -->
|
||||
<xpath expr="//field[@name='order_line']/form//field[@name='analytic_tag_ids']" position="attributes">
|
||||
<attribute name="groups">analytic.group_analytic_tags</attribute>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -49,10 +45,6 @@
|
||||
<field name="origin" position="attributes">
|
||||
<attribute name="invisible">1</attribute>
|
||||
</field>
|
||||
<field name="state" position="after">
|
||||
<!-- State field is not sufficient to define what is the next step of the purchase-->
|
||||
<field name="invoice_status"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -61,9 +53,6 @@
|
||||
<field name="model">purchase.order</field>
|
||||
<field name="inherit_id" ref="purchase.view_purchase_order_filter"/>
|
||||
<field name="arch" type="xml">
|
||||
<group expand="0" position="inside">
|
||||
<filter string="Billing Status" name="invoice_status_groupby" context="{'group_by': 'invoice_status'}"/>
|
||||
</group>
|
||||
<field name="name" position="attributes">
|
||||
<attribute name="string">Reference or Origin</attribute>
|
||||
<attribute name="filter_domain">['|', ('name', 'ilike', self), ('origin', 'ilike', self)]</attribute>
|
||||
@@ -129,7 +118,7 @@
|
||||
<field name="price_unit"/>
|
||||
</field>
|
||||
<field name="product_qty" position="before">
|
||||
<field name="account_analytic_id" groups="analytic.group_analytic_accounting"/>
|
||||
<field name="account_analytic_id" groups="purchase.group_analytic_accounting"/>
|
||||
<field name="currency_id" invisible="1"/>
|
||||
</field>
|
||||
<field name="date_planned" position="after">
|
||||
@@ -144,7 +133,7 @@
|
||||
<field name="inherit_id" ref="purchase.purchase_order_line_search"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="partner_id" position="after">
|
||||
<field name="account_analytic_id" groups="analytic.group_analytic_accounting"/>
|
||||
<field name="account_analytic_id" groups="purchase.group_analytic_accounting"/>
|
||||
</field>
|
||||
<group expand="0" position="inside">
|
||||
<filter string="Analytic Account" name="account_analytic_groupby" context="{'group_by': 'account_analytic_id'}"/>
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
from . import sale
|
||||
from . import sale_report
|
||||
@@ -1,25 +0,0 @@
|
||||
# Copyright (C) 2015-2019 Akretion (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
|
||||
{
|
||||
'name': 'Sale Margin No Onchange',
|
||||
'version': '12.0.1.0.0',
|
||||
'category': 'Sales',
|
||||
'license': 'AGPL-3',
|
||||
'summary': 'Copy standard price on sale order line and compute margins',
|
||||
'description': """
|
||||
This module copies the field *standard_price* of the product on the sale order line when the sale order line is created and then computes the margin of the sale order and the sale order line (in the currency of the quotation, in the currency of the company and the margin rate).
|
||||
|
||||
I decided to develop this module as an alternative to the OCA sale margin modules because I wanted a small and simple module. The module *account_invoice_margin*, available in the same Github repository, do the same thing on customer invoices.
|
||||
|
||||
This module has been written by Alexis de Lattre from Akretion
|
||||
<alexis.delattre@akretion.com>.
|
||||
""",
|
||||
'author': 'Akretion',
|
||||
'website': 'http://www.akretion.com',
|
||||
'depends': ['sale'],
|
||||
'data': ['sale_view.xml'],
|
||||
'installable': True,
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
# Copyright (C) 2015-2019 Akretion (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
|
||||
from odoo import api, fields, models
|
||||
import odoo.addons.decimal_precision as dp
|
||||
|
||||
|
||||
class SaleOrderLine(models.Model):
|
||||
_inherit = 'sale.order.line'
|
||||
|
||||
# Also defined in bi_sale_company_currency
|
||||
company_currency_id = fields.Many2one(
|
||||
related='order_id.company_id.currency_id',
|
||||
store=True, string='Company Currency')
|
||||
standard_price_company_currency = fields.Float(
|
||||
string='Cost Price in Company Currency', readonly=True,
|
||||
digits=dp.get_precision('Product Price'),
|
||||
help="Cost price in company currency in the unit of measure "
|
||||
"of the sale order line")
|
||||
standard_price_sale_currency = fields.Float(
|
||||
string='Cost Price in Sale Currency', readonly=True,
|
||||
compute='_compute_margin', store=True,
|
||||
digits=dp.get_precision('Product Price'),
|
||||
help="Cost price in sale currency in the unit of measure "
|
||||
"of the sale order line")
|
||||
margin_sale_currency = fields.Monetary(
|
||||
string='Margin in Sale Currency', readonly=True, store=True,
|
||||
compute='_compute_margin', currency_field='currency_id')
|
||||
margin_company_currency = fields.Monetary(
|
||||
string='Margin in Company Currency', readonly=True, store=True,
|
||||
compute='_compute_margin', currency_field='company_currency_id')
|
||||
margin_rate = fields.Float(
|
||||
string="Margin Rate", readonly=True, store=True,
|
||||
compute='_compute_margin',
|
||||
digits=(16, 2), help="Margin rate in percentage of the sale price")
|
||||
|
||||
@api.depends(
|
||||
'standard_price_company_currency', 'order_id.pricelist_id.currency_id',
|
||||
'order_id.date_order', 'product_uom_qty', 'price_subtotal',
|
||||
'order_id.company_id')
|
||||
def _compute_margin(self):
|
||||
for line in self:
|
||||
standard_price_sale_cur = 0.0
|
||||
margin_sale_cur = 0.0
|
||||
margin_comp_cur = 0.0
|
||||
margin_rate = 0.0
|
||||
order_cur = line.order_id.pricelist_id.currency_id
|
||||
company = line.order_id.company_id
|
||||
company_cur = company.currency_id
|
||||
if order_cur and company_cur:
|
||||
date = line.order_id.date_order
|
||||
standard_price_sale_cur =\
|
||||
company_cur._convert(
|
||||
line.standard_price_company_currency, order_cur,
|
||||
company, date)
|
||||
margin_sale_cur =\
|
||||
line.price_subtotal\
|
||||
- line.product_uom_qty * standard_price_sale_cur
|
||||
margin_comp_cur = order_cur._convert(
|
||||
margin_sale_cur, company_cur, company, date)
|
||||
if line.price_subtotal:
|
||||
margin_rate = 100 * margin_sale_cur / line.price_subtotal
|
||||
line.standard_price_sale_currency = standard_price_sale_cur
|
||||
line.margin_sale_currency = margin_sale_cur
|
||||
line.margin_company_currency = margin_comp_cur
|
||||
line.margin_rate = margin_rate
|
||||
|
||||
# We want to copy standard_price on sale order line
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
if vals.get('product_id'):
|
||||
pp = self.env['product.product'].browse(vals['product_id'])
|
||||
std_price = pp.standard_price
|
||||
sale_uom_id = vals.get('product_uom')
|
||||
if sale_uom_id and sale_uom_id != pp.uom_id.id:
|
||||
sale_uom = self.env['uom.uom'].browse(sale_uom_id)
|
||||
# convert from product UoM to sale UoM
|
||||
std_price = pp.uom_id._compute_price(
|
||||
pp.standard_price, sale_uom)
|
||||
vals['standard_price_company_currency'] = std_price
|
||||
return super(SaleOrderLine, self).create(vals)
|
||||
|
||||
def write(self, vals):
|
||||
if not vals:
|
||||
vals = {}
|
||||
if 'product_id' in vals or 'product_uom' in vals:
|
||||
for sol in self:
|
||||
# product_uom and product_id are required fields
|
||||
if 'product_id' in vals:
|
||||
pp = self.env['product.product'].browse(vals['product_id'])
|
||||
else:
|
||||
pp = sol.product_id
|
||||
if 'product_uom' in vals:
|
||||
sale_uom = self.env['uom.uom'].browse(
|
||||
vals['product_uom'])
|
||||
else:
|
||||
sale_uom = sol.product_uom
|
||||
std_price = pp.standard_price
|
||||
if sale_uom != pp.uom_id:
|
||||
std_price = pp.uom_id._compute_price(std_price, sale_uom)
|
||||
sol.write({'standard_price_company_currency': std_price})
|
||||
return super(SaleOrderLine, self).write(vals)
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
# Also defined in bi_sale_company_currency
|
||||
company_currency_id = fields.Many2one(
|
||||
related='company_id.currency_id', store=True,
|
||||
string="Company Currency")
|
||||
margin_sale_currency = fields.Monetary(
|
||||
string='Margin in Sale Currency',
|
||||
currency_field='currency_id',
|
||||
readonly=True, compute='_compute_margin', store=True)
|
||||
margin_company_currency = fields.Monetary(
|
||||
string='Margin in Company Currency',
|
||||
currency_field='company_currency_id',
|
||||
readonly=True, compute='_compute_margin', store=True)
|
||||
|
||||
@api.depends(
|
||||
'order_line.margin_sale_currency',
|
||||
'order_line.margin_company_currency')
|
||||
def _compute_margin(self):
|
||||
for order in self:
|
||||
margin_sale_cur = 0.0
|
||||
margin_comp_cur = 0.0
|
||||
for sol in order.order_line:
|
||||
margin_sale_cur += sol.margin_sale_currency
|
||||
margin_comp_cur += sol.margin_company_currency
|
||||
order.margin_sale_currency = margin_sale_cur
|
||||
order.margin_company_currency = margin_comp_cur
|
||||
@@ -1,19 +0,0 @@
|
||||
# Copyright 2018-2019 Akretion (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class SaleReport(models.Model):
|
||||
_inherit = 'sale.report'
|
||||
|
||||
margin = fields.Float(string='Margin', readonly=True)
|
||||
|
||||
def _query(self, with_clause='', fields={}, groupby='', from_clause=''):
|
||||
fields['margin_company_currency'] =\
|
||||
", SUM(l.margin_company_currency) AS margin"
|
||||
res = super(SaleReport, self)._query(
|
||||
with_clause=with_clause, fields=fields, groupby=groupby,
|
||||
from_clause=from_clause)
|
||||
return res
|
||||
@@ -1,53 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2015-2019 Akretion (http://www.akretion.com/)
|
||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
<odoo>
|
||||
|
||||
|
||||
<record id="view_order_form" model="ir.ui.view">
|
||||
<field name="name">margin.sale.order.form</field>
|
||||
<field name="model">sale.order</field>
|
||||
<field name="inherit_id" ref="sale.view_order_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<group name="technical" position="inside">
|
||||
<field name="margin_sale_currency" string="Margin"
|
||||
groups="account.group_account_user"/>
|
||||
<field name="margin_company_currency"
|
||||
groups="account.group_account_user"/>
|
||||
<field name="company_currency_id" invisible="1"/>
|
||||
</group>
|
||||
<xpath expr="//field[@name='order_line']/form//field[@name='analytic_tag_ids']/.." position="after">
|
||||
<field name="standard_price_sale_currency" groups="base.group_no_one"/>
|
||||
<field name="standard_price_company_currency" groups="base.group_no_one"/>
|
||||
<field name="margin_sale_currency" groups="base.group_no_one"/>
|
||||
<field name="margin_company_currency" groups="base.group_no_one"/>
|
||||
<label for="margin_rate"/>
|
||||
<div name="margin_rate">
|
||||
<field name="margin_rate" groups="base.group_no_one" class="oe_inline"/> %
|
||||
</div>
|
||||
<field name="company_currency_id" invisible="1"/>
|
||||
<field name="currency_id" invisible="1"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_order_line_tree" model="ir.ui.view">
|
||||
<field name="name">margin.sale.order.line.tree</field>
|
||||
<field name="model">sale.order.line</field>
|
||||
<field name="inherit_id" ref="sale.view_order_line_tree" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="price_subtotal" position="after">
|
||||
<field name="standard_price_company_currency" groups="account.group_account_user"/>
|
||||
<field name="margin_company_currency" groups="account.group_account_user"/>
|
||||
<field name="margin_rate" groups="account.group_account_user"/>
|
||||
<field name="company_currency_id" invisible="1"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</odoo>
|
||||
@@ -1,3 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import models
|
||||
@@ -1,22 +0,0 @@
|
||||
# Copyright 2019 Akretion France (http://www.akretion.com/)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
'name': 'Sale Order Route',
|
||||
'version': '12.0.1.0.0',
|
||||
'category': 'Sales',
|
||||
'license': 'AGPL-3',
|
||||
'summary': 'Set route on sale order',
|
||||
'description': """
|
||||
This small module adds the possibility to set a route on a sale order. Upon sale order confirmation, the route will be copied to all the sale order lines.
|
||||
|
||||
This module has been written by Alexis de Lattre from Akretion
|
||||
<alexis.delattre@akretion.com>.
|
||||
""",
|
||||
'author': 'Akretion',
|
||||
'website': 'http://www.akretion.com',
|
||||
'depends': ['sale_stock'],
|
||||
'data': ['views/sale_order.xml'],
|
||||
'installable': True,
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import sale_order
|
||||
@@ -1,22 +0,0 @@
|
||||
# Copyright 2019 Akretion France (http://www.akretion.com/)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
route_id = fields.Many2one(
|
||||
'stock.location.route', string='Route',
|
||||
ondelete='restrict', readonly=True,
|
||||
states={'draft': [('readonly', False)], 'sent': [('readonly', False)]},
|
||||
domain=[('sale_selectable', '=', True)])
|
||||
|
||||
def _action_confirm(self):
|
||||
for order in self.filtered(lambda o: o.route_id):
|
||||
order.order_line.filtered(
|
||||
lambda l: l.product_id.type in ('product', 'consu')).write(
|
||||
{'route_id': order.route_id.id})
|
||||
super(SaleOrder, self)._action_confirm()
|
||||
@@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2019 Akretion France (http://www.akretion.com/)
|
||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
<odoo>
|
||||
|
||||
<record id="view_order_form_inherit_sale_stock" model="ir.ui.view">
|
||||
<field name="name">sale.order.route.form</field>
|
||||
<field name="model">sale.order</field>
|
||||
<field name="inherit_id" ref="sale_stock.view_order_form_inherit_sale_stock"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="partner_shipping_id" position="after">
|
||||
<field name="route_id" options="{'no_create_edit': True}"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -1,22 +0,0 @@
|
||||
# © 2019 Akretion (http://www.akretion.com)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
|
||||
{
|
||||
'name': 'Sale Product Tree Default',
|
||||
'version': '12.0.1.0.0',
|
||||
'category': 'Product',
|
||||
'license': 'AGPL-3',
|
||||
'summary': 'Tree view by default instead of kanban for Products',
|
||||
'description': """
|
||||
Replace default kanban view by tree view for product menu in sale
|
||||
main menu
|
||||
""",
|
||||
'author': 'Akretion',
|
||||
'website': 'http://www.akretion.com',
|
||||
'depends': ['sale'],
|
||||
'data': [
|
||||
'views/product_template.xml'
|
||||
],
|
||||
'installable': True,
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<odoo>
|
||||
|
||||
<record id="sale.product_template_action" model="ir.actions.act_window">
|
||||
<field name="view_mode">tree,form,kanban,activity</field>
|
||||
<field name="view_id" ref="product.product_template_tree_view"/>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -1,5 +1,5 @@
|
||||
# Copyright 2015-2019 Akretion France (http://www.akretion.com/)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2015-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2015-2019 Akretion France (http://www.akretion.com/)
|
||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
© 2015-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
from . import sale_stock
|
||||
from . import wizard
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models, fields, api
|
||||
from odoo import models, fields
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
@@ -10,41 +10,3 @@ class SaleOrder(models.Model):
|
||||
|
||||
warehouse_id = fields.Many2one(track_visibility='onchange')
|
||||
incoterm = fields.Many2one(track_visibility='onchange')
|
||||
picking_status = fields.Selection([
|
||||
('delivered', 'Fully Delivered'),
|
||||
('partially_delivered', 'Partially Delivered'),
|
||||
('to_deliver', 'To Deliver'),
|
||||
('cancel', 'Delivery Cancelled'),
|
||||
('no', 'Nothing to Deliver')
|
||||
], string='Picking Status', compute='_compute_picking_status',
|
||||
store=True, readonly=True)
|
||||
|
||||
@api.depends('state', 'picking_ids.state')
|
||||
def _compute_picking_status(self):
|
||||
"""
|
||||
Compute the picking status for the SO. Possible statuses:
|
||||
- no: if the SO is not in status 'sale' nor 'done', we consider that
|
||||
there is nothing to deliver. This is also the default value if the
|
||||
conditions of no other status is met.
|
||||
- cancel: all pickings are cancelled
|
||||
- delivered: if all pickings are done or cancel.
|
||||
- partially_delivered: If at least one picking is done.
|
||||
- to_deliver: if all pickings are in confirmed, assigned, waiting or
|
||||
cancel state.
|
||||
"""
|
||||
for order in self:
|
||||
picking_status = 'no'
|
||||
if order.state in ('sale', 'done') and order.picking_ids:
|
||||
pstates = [
|
||||
picking.state for picking in order.picking_ids]
|
||||
if all([state == 'cancel' for state in pstates]):
|
||||
picking_status = 'cancel'
|
||||
elif all([state in ('done', 'cancel') for state in pstates]):
|
||||
picking_status = 'delivered'
|
||||
elif any([state == 'done' for state in pstates]):
|
||||
picking_status = 'partially_delivered'
|
||||
elif all([
|
||||
state in ('confirmed', 'assigned', 'waiting', 'cancel')
|
||||
for state in pstates]):
|
||||
picking_status = 'to_deliver'
|
||||
order.picking_status = picking_status
|
||||
|
||||
@@ -30,41 +30,4 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_order_form" model="ir.ui.view">
|
||||
<field name="name">sale_stock_usability.order.form</field>
|
||||
<field name="model">sale.order</field>
|
||||
<field name="inherit_id" ref="sale.view_order_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="pricelist_id" position="after">
|
||||
<field name="picking_status"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_order_tree" model="ir.ui.view">
|
||||
<field name="name">sale_stock_usability.order.tree</field>
|
||||
<field name="model">sale.order</field>
|
||||
<field name="inherit_id" ref="sale.view_order_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="invoice_status" position="after">
|
||||
<field name="picking_status"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_sales_order_filter" model="ir.ui.view">
|
||||
<field name="name">sale_stock_usability.order.search</field>
|
||||
<field name="model">sale.order</field>
|
||||
<field name="inherit_id" ref="sale.view_sales_order_filter"/>
|
||||
<field name="arch" type="xml">
|
||||
<filter name="my_sale_orders_filter" position="after">
|
||||
<separator/>
|
||||
<filter string="Not Fully Delivered" name="not_fully_delivered"
|
||||
domain="[('picking_status', 'in', ('to_deliver', 'partially_delivered'))]"/>
|
||||
<filter string="Fully Delivered" name="fully_delivered"
|
||||
domain="[('picking_status', '=', 'delivered')]"/>
|
||||
</filter>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
||||
1
sale_stock_usability/wizard/__init__.py
Normal file
1
sale_stock_usability/wizard/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import stock_return_picking
|
||||
18
sale_stock_usability/wizard/stock_return_picking.py
Normal file
18
sale_stock_usability/wizard/stock_return_picking.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Copyright 2017-2019 Akretion France (https://akretion.com/)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models, api
|
||||
|
||||
|
||||
class StockReturnPicking(models.TransientModel):
|
||||
_inherit = 'stock.return.picking'
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
res = super(StockReturnPicking, self).default_get(fields)
|
||||
if res.get('product_return_moves'):
|
||||
for line in res['product_return_moves']:
|
||||
if len(line) == 3:
|
||||
line[2]['to_refund_so'] = True
|
||||
return res
|
||||
@@ -1,4 +1,5 @@
|
||||
# Copyright (C) 2015-2019 Akretion (http://www.akretion.com)
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (C) 2015-2018 Akretion (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
@@ -30,12 +31,12 @@ class AccountInvoice(models.Model):
|
||||
# from pprint import pprint
|
||||
# pprint(res1)
|
||||
res2 = []
|
||||
if len(res1) == 1 and not list(res1)[0]:
|
||||
if len(res1) == 1 and not res1.keys()[0]:
|
||||
# No order at all
|
||||
for line in list(res1.values())[0]['lines']:
|
||||
for line in res1.values()[0]['lines']:
|
||||
res2.append({'line': line})
|
||||
else:
|
||||
for order, ldict in res1.items():
|
||||
for order, ldict in res1.iteritems():
|
||||
res2.append({'categ': order})
|
||||
for line in ldict['lines']:
|
||||
res2.append({'line': line})
|
||||
|
||||
@@ -24,4 +24,15 @@ because the parent menu entry is in the sale module -->
|
||||
sequence="50"/>
|
||||
|
||||
|
||||
<record id="product_pricelist_view" model="ir.ui.view">
|
||||
<field name="model">product.pricelist</field>
|
||||
<field name="inherit_id" ref="product.product_pricelist_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[@groups='product.group_pricelist_item']" position="attributes">
|
||||
<div name="groups">product.group_pricelist_item,base_usability.group_nobody</div>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
from odoo import models, fields, api
|
||||
from odoo.tools import float_is_zero
|
||||
from collections import OrderedDict
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
|
||||
@@ -48,9 +48,6 @@
|
||||
<field name="amount_total" position="before">
|
||||
<field name="amount_untaxed" sum="Total Untaxed"/>
|
||||
</field>
|
||||
<field name="state" position="attributes">
|
||||
<attribute name="invisible">0</attribute>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
@@ -16,16 +16,13 @@ Stock Account Usability
|
||||
|
||||
The usability enhancements include:
|
||||
|
||||
* activate the refund option by default in return wizard on pickings
|
||||
|
||||
* add ability to select a stock location on the inventory valuation report
|
||||
|
||||
* TODO update the list
|
||||
|
||||
This module has been written by Alexis de Lattre from Akretion <alexis.delattre@akretion.com>.
|
||||
""",
|
||||
'author': 'Akretion',
|
||||
'website': 'http://www.akretion.com',
|
||||
'depends': ['stock_account'],
|
||||
'data': ['wizard/stock_quantity_history_view.xml'],
|
||||
'data': [],
|
||||
'installable': True,
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
diff --git a/addons/stock_account/models/product.py b/addons/stock_account/models/product.py
|
||||
index 0622c16d2b5..c078ac54324 100644
|
||||
--- a/addons/stock_account/models/product.py
|
||||
+++ b/addons/stock_account/models/product.py
|
||||
@@ -239,7 +239,7 @@ class ProductProduct(models.Model):
|
||||
|
||||
for product in self:
|
||||
if product.cost_method in ['standard', 'average']:
|
||||
- qty_available = product.with_context(company_owned=True, owner_id=False).qty_available
|
||||
+ qty_available = product.with_context(owner_id=False).qty_available
|
||||
price_used = product.standard_price
|
||||
if to_date:
|
||||
price_used = product.get_history_price(
|
||||
@@ -252,7 +252,7 @@ class ProductProduct(models.Model):
|
||||
if to_date:
|
||||
if product.product_tmpl_id.valuation == 'manual_periodic':
|
||||
product.stock_value = product_values[product.id]
|
||||
- product.qty_at_date = product.with_context(company_owned=True, owner_id=False).qty_available
|
||||
+ product.qty_at_date = product.with_context(owner_id=False).qty_available
|
||||
product.stock_fifo_manual_move_ids = StockMove.browse(product_move_ids[product.id])
|
||||
elif product.product_tmpl_id.valuation == 'real_time':
|
||||
valuation_account_id = product.categ_id.property_stock_valuation_account_id.id
|
||||
@@ -1,2 +0,0 @@
|
||||
from . import stock_return_picking
|
||||
from . import stock_quantity_history
|
||||
@@ -1,35 +0,0 @@
|
||||
# Copyright 2019 Akretion France (http://www.akretion.com/)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class StockQuantityHistory(models.TransientModel):
|
||||
_inherit = 'stock.quantity.history'
|
||||
|
||||
def open_table(self):
|
||||
action = super(StockQuantityHistory, self).open_table()
|
||||
if self.location_id and self.env.context.get('valuation'):
|
||||
# When we have 'valuation' in context
|
||||
# in both cases ('current inventory' and 'at specific date')
|
||||
# it returns an action on product.product,
|
||||
# the only difference is the context.
|
||||
# We have to make the same modifications, but
|
||||
# when self.compute_at_date, action['context'] is a dict
|
||||
# otherwize, action['context'] is a string
|
||||
if self.compute_at_date:
|
||||
# insert "location" in context for qty computation
|
||||
action['context']['location'] = self.location_id.id
|
||||
# When company_owned=True, the 'location' given in the
|
||||
# context is not taken into account
|
||||
# IMPORTANT: also requires a patch on the stock_account
|
||||
# module. Patch provided in this module.
|
||||
action['context']['company_owned'] = False
|
||||
else:
|
||||
action['context'] = {
|
||||
'location': self.location_id.id,
|
||||
'create': False,
|
||||
'edit': False,
|
||||
}
|
||||
return action
|
||||
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2019 Akretion France (http://www.akretion.com/)
|
||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
|
||||
<odoo>
|
||||
|
||||
|
||||
<record id="view_stock_quantity_history" model="ir.ui.view">
|
||||
<field name="name">stock_account_usability.stock.quantity.history.form</field>
|
||||
<field name="model">stock.quantity.history</field>
|
||||
<field name="inherit_id" ref="stock_account.view_stock_quantity_history"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="date" position="after">
|
||||
<field name="location_id"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</odoo>
|
||||
@@ -1,19 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2019 Akretion France (https://akretion.com/)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, models
|
||||
from odoo import models, fields
|
||||
|
||||
|
||||
class StockReturnPicking(models.TransientModel):
|
||||
_inherit = 'stock.return.picking'
|
||||
class StockReturnPickingLine(models.TransientModel):
|
||||
_inherit = 'stock.return.picking.line'
|
||||
|
||||
# Set to_refund to True by default
|
||||
@api.model
|
||||
def default_get(self, fields_list):
|
||||
res = super(StockReturnPicking, self).default_get(fields_list)
|
||||
if isinstance(res.get('product_return_moves'), list):
|
||||
for l in res['product_return_moves']:
|
||||
if len(l) == 3 and isinstance(l[2], dict):
|
||||
l[2]['to_refund'] = True
|
||||
return res
|
||||
to_refund = fields.Boolean(default=True)
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
from . import stock_inventory
|
||||
@@ -1,25 +0,0 @@
|
||||
# Copyright 2016-2019 Akretion France (http://www.akretion.com)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
|
||||
{
|
||||
'name': 'Stock Inventory Validation ODS',
|
||||
'version': '12.0.1.0.0',
|
||||
'category': 'Tools',
|
||||
'license': 'AGPL-3',
|
||||
'summary': 'Adds a Py3o ODS report on inventories',
|
||||
'description': """
|
||||
Stock Inventory Validation ODS
|
||||
==============================
|
||||
|
||||
This module will add a Py3o ODS report on Stock Inventories.
|
||||
|
||||
This module has been written by Alexis de Lattre from Akretion <alexis.delattre@akretion.com>.
|
||||
""",
|
||||
'author': "Akretion",
|
||||
'website': 'http://www.akretion.com',
|
||||
'depends': ['stock_inventory_valuation', 'report_py3o'],
|
||||
'data': ['report.xml'],
|
||||
'installable': True,
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user