Add modules service_line_qty_update_base service_line_qty_update_purchase
This commit is contained in:
1
service_line_qty_update_base/__init__.py
Normal file
1
service_line_qty_update_base/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import wizard
|
||||||
18
service_line_qty_update_base/__manifest__.py
Normal file
18
service_line_qty_update_base/__manifest__.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Copyright 2020 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': 'Service Line Qty Update Base',
|
||||||
|
'version': '12.0.1.0.0',
|
||||||
|
'category': 'Tools',
|
||||||
|
'license': 'AGPL-3',
|
||||||
|
'summary': 'Update delivery qty on service lines - Base module',
|
||||||
|
'author': 'Akretion',
|
||||||
|
'website': 'http://www.akretion.com',
|
||||||
|
'depends': ['product'],
|
||||||
|
'data': [
|
||||||
|
'wizard/service_qty_update_view.xml',
|
||||||
|
],
|
||||||
|
'installable': True,
|
||||||
|
}
|
||||||
1
service_line_qty_update_base/wizard/__init__.py
Normal file
1
service_line_qty_update_base/wizard/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import service_qty_update
|
||||||
70
service_line_qty_update_base/wizard/service_qty_update.py
Normal file
70
service_line_qty_update_base/wizard/service_qty_update.py
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
# Copyright 2020 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
|
||||||
|
from odoo.tools import float_compare, float_is_zero
|
||||||
|
import odoo.addons.decimal_precision as dp
|
||||||
|
from odoo.exceptions import UserError
|
||||||
|
|
||||||
|
|
||||||
|
class ServiceQtyUpdate(models.TransientModel):
|
||||||
|
_name = 'service.qty.update'
|
||||||
|
_description = 'Wizard to update delivery qty on service lines'
|
||||||
|
|
||||||
|
line_ids = fields.One2many('service.qty.update.line', 'parent_id', string="Lines")
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
self.ensure_one()
|
||||||
|
prec = self.env['decimal.precision'].precision_get('Product Unit of Measure')
|
||||||
|
for line in self:
|
||||||
|
if float_compare(line.post_delivered_qty, line.order_qty, precision_digits=prec) > 0:
|
||||||
|
raise UserError(_(
|
||||||
|
"On line '%s', the total delivered qty (%s) is superior to the ordered qty (%s).") % (line.name, line.post_delivered_qty, line.order_qty))
|
||||||
|
fc_added = float_compare(line.added_delivered_qty, 0, precision_digits=prec)
|
||||||
|
if fc_added < 0:
|
||||||
|
raise UserError(_(
|
||||||
|
"On line '%s', the added quantity is negative.") % line.name)
|
||||||
|
if fc_added > 0:
|
||||||
|
line.process_line()
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
class ServiceQtyUpdateLine(models.TransientModel):
|
||||||
|
_name = 'service.qty.update.line'
|
||||||
|
_description = 'Lines of the wizard that updates delivery qty on service lines'
|
||||||
|
|
||||||
|
parent_id = fields.Many2one(
|
||||||
|
'service.qty.update', string='Wizard', ondelete='cascade')
|
||||||
|
product_id = fields.Many2one('product.product', string='Product', readonly=True)
|
||||||
|
name = fields.Char(string='Description', readonly=True)
|
||||||
|
order_qty = fields.Float(
|
||||||
|
string='Order Qty',
|
||||||
|
digits=dp.get_precision('Product Unit of Measure'),
|
||||||
|
readonly=True)
|
||||||
|
pre_delivered_qty = fields.Float(
|
||||||
|
string='Current Delivered Qty',
|
||||||
|
digits=dp.get_precision('Product Unit of Measure'),
|
||||||
|
readonly=True)
|
||||||
|
added_delivered_qty = fields.Float(
|
||||||
|
string='Added Delivered Qty',
|
||||||
|
digits=dp.get_precision('Product Unit of Measure'))
|
||||||
|
post_delivered_qty = fields.Float(
|
||||||
|
compute='_compute_post_delivered_qty',
|
||||||
|
string='Total Delivered Qty',
|
||||||
|
digits=dp.get_precision('Product Unit of Measure'))
|
||||||
|
uom_id = fields.Many2one('uom.uom', string='UoM', readonly=True)
|
||||||
|
comment = fields.Char(string='Comment')
|
||||||
|
|
||||||
|
@api.depends('pre_delivered_qty', 'added_delivered_qty')
|
||||||
|
def _compute_post_delivered_qty(self):
|
||||||
|
for line in self:
|
||||||
|
line.post_delivered_qty = line.pre_delivered_qty + line.added_delivered_qty
|
||||||
|
|
||||||
|
def process_line(self):
|
||||||
|
# Write and message_post
|
||||||
|
return
|
||||||
|
|
||||||
|
# sale : qty_delivered
|
||||||
|
# purchase : qty_received
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright 2020 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="service_qty_update_form" model="ir.ui.view">
|
||||||
|
<field name="model">service.qty.update</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form>
|
||||||
|
<group name="main">
|
||||||
|
<field name="line_ids" editable="bottom" nolabel="1" options="{'no_create': True}">
|
||||||
|
<tree>
|
||||||
|
<field name="product_id"/>
|
||||||
|
<field name="name"/>
|
||||||
|
<field name="order_qty"/>
|
||||||
|
<field name="pre_delivered_qty"/>
|
||||||
|
<field name="added_delivered_qty"/>
|
||||||
|
<field name="post_delivered_qty"/>
|
||||||
|
<field name="uom_id" groups="uom.group_uom"/>
|
||||||
|
<field name="comment"/>
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
</group>
|
||||||
|
<footer>
|
||||||
|
<button name="run" type="object" string="Validate" class="btn-primary"/>
|
||||||
|
<button special="cancel" string="Cancel" class="btn-default"/>
|
||||||
|
</footer>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="service_qty_update_action" model="ir.actions.act_window">
|
||||||
|
<field name="name">Service Order Lines - Update Delivered Qty</field>
|
||||||
|
<field name="res_model">service.qty.update</field>
|
||||||
|
<field name="view_mode">form</field>
|
||||||
|
<field name="target">new</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
|
||||||
|
</odoo>
|
||||||
2
service_line_qty_update_purchase/__init__.py
Normal file
2
service_line_qty_update_purchase/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
from . import models
|
||||||
|
from . import wizard
|
||||||
18
service_line_qty_update_purchase/__manifest__.py
Normal file
18
service_line_qty_update_purchase/__manifest__.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Copyright 2020 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': 'Service Line Qty Update Purchase',
|
||||||
|
'version': '12.0.1.0.0',
|
||||||
|
'category': 'Tools',
|
||||||
|
'license': 'AGPL-3',
|
||||||
|
'summary': 'Update delivery qty on service lines - Purchase module',
|
||||||
|
'author': 'Akretion',
|
||||||
|
'website': 'http://www.akretion.com',
|
||||||
|
'depends': ['purchase'],
|
||||||
|
'data': [
|
||||||
|
'views/purchase_order.xml',
|
||||||
|
],
|
||||||
|
'installable': True,
|
||||||
|
}
|
||||||
1
service_line_qty_update_purchase/models/__init__.py
Normal file
1
service_line_qty_update_purchase/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import purchase_order
|
||||||
20
service_line_qty_update_purchase/models/purchase_order.py
Normal file
20
service_line_qty_update_purchase/models/purchase_order.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# Copyright 2020 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 PurchaseOrder(models.Model):
|
||||||
|
_inherit = 'purchase.order'
|
||||||
|
|
||||||
|
has_service = fields.Boolean(compute='_compute_has_service')
|
||||||
|
|
||||||
|
def _compute_has_service(self):
|
||||||
|
for order in self:
|
||||||
|
has_service = False
|
||||||
|
for l in order.order_line:
|
||||||
|
if l.product_id.type == 'service':
|
||||||
|
has_service = True
|
||||||
|
break
|
||||||
|
order.has_service = has_service
|
||||||
27
service_line_qty_update_purchase/views/purchase_order.xml
Normal file
27
service_line_qty_update_purchase/views/purchase_order.xml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright 2020 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="purchase_order_form" model="ir.ui.view">
|
||||||
|
<field name="name">purchase.order.form</field>
|
||||||
|
<field name="model">purchase.order</field>
|
||||||
|
<field name="inherit_id" ref="purchase.purchase_order_form"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<button name="action_view_invoice" position="after">
|
||||||
|
<button name="%(service_line_qty_update_base.service_qty_update_action)d" type="action" string="Update Service Qty" attrs="{'invisible': ['|', ('state', 'not in', ('purchase', 'done')), ('has_service', '=', False)]}"/>
|
||||||
|
<field name="has_service" invisible="1"/>
|
||||||
|
</button>
|
||||||
|
<xpath expr="//field[@name='order_line']/tree/field[@name='qty_received']" position="attributes">
|
||||||
|
<attribute name="readonly">1</attribute>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
|
||||||
|
</odoo>
|
||||||
1
service_line_qty_update_purchase/wizard/__init__.py
Normal file
1
service_line_qty_update_purchase/wizard/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import service_qty_update
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
# Copyright 2020 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
|
||||||
|
from odoo.tools import float_compare
|
||||||
|
from odoo.exceptions import UserError
|
||||||
|
|
||||||
|
|
||||||
|
class ServiceQtyUpdate(models.TransientModel):
|
||||||
|
_inherit = 'service.qty.update'
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def default_get(self, fields_list):
|
||||||
|
res = super().default_get(fields_list)
|
||||||
|
prec = self.env['decimal.precision'].precision_get('Product Unit of Measure')
|
||||||
|
if self._context.get('active_model') == 'purchase.order' and self._context.get('active_id'):
|
||||||
|
lines = []
|
||||||
|
order = self.env['purchase.order'].browse(self._context['active_id'])
|
||||||
|
for l in order.order_line.filtered(lambda x: x.product_id.type == 'service'):
|
||||||
|
if float_compare(l.product_qty, l.qty_received, precision_digits=prec) > 0:
|
||||||
|
lines.append((0, 0, {
|
||||||
|
'purchase_line_id': l.id,
|
||||||
|
'product_id': l.product_id.id,
|
||||||
|
'name': l.name,
|
||||||
|
'order_qty': l.product_qty,
|
||||||
|
'pre_delivered_qty': l.qty_received,
|
||||||
|
'uom_id': l.product_uom.id,
|
||||||
|
}))
|
||||||
|
if lines:
|
||||||
|
res['line_ids'] = lines
|
||||||
|
else:
|
||||||
|
raise UserError(_(
|
||||||
|
"All service lines are fully received."))
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
class ServiceQtyUpdateLine(models.TransientModel):
|
||||||
|
_inherit = 'service.qty.update.line'
|
||||||
|
|
||||||
|
purchase_line_id = fields.Many2one('purchase.order.line', string='Purchase Line', readonly=True)
|
||||||
|
|
||||||
|
def process_line(self):
|
||||||
|
po_line = self.purchase_line_id
|
||||||
|
if po_line:
|
||||||
|
po_line.write({'qty_received': self.post_delivered_qty})
|
||||||
|
body = """
|
||||||
|
<p>Received qty updated on service line <em>%s</em>:
|
||||||
|
<ul>
|
||||||
|
<li>Added received qty: %s</li>
|
||||||
|
<li>Total received qty: %s</li>
|
||||||
|
</ul></p>
|
||||||
|
""" % (self.added_delivered_qty, self.post_delivered_qty)
|
||||||
|
if self.comment:
|
||||||
|
body += '<p>Comment: %s</p>' % self.comment
|
||||||
|
po_line.order_id.message_post(body=body)
|
||||||
|
return super().process_line()
|
||||||
Reference in New Issue
Block a user