Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] custom_picking_delivery_note_report: module to add MO delivery … #234

Open
wants to merge 10 commits into
base: 18.0
Choose a base branch
from
Open
Empty file.
12 changes: 12 additions & 0 deletions custom_picking_delivery_note_report/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
'name': 'MO delivery note(Inventory)',
'description': "Module used to add MO delivery note report in stock(inventory) module",
'installable': True,
'application': False,
'depends': ['stock', 'mrp'],
'data': [
'report/mo_report_deliveryslip_template.xml',
'report/custom_picking_delivery_note_report.xml',
],
'license':'LGPL-3'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="action_report_custom_picking_delivery_note" model="ir.actions.report">
<field name="name">MO Delivery Note</field>
<field name="model">stock.picking</field>
<field name="report_type">qweb-pdf</field>

<field name="report_name">custom_picking_delivery_note_report.mo_report_deliveryslip_template</field>

<field name="print_report_name">'MO Delivery Note - %s - %s' % (object.partner_id.name or '', object.name)</field>
<field name="binding_model_id" ref="stock.model_stock_picking"/>
<field name="binding_type">report</field>
</record>
</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<template id="mo_report_deliveryslip_template">
<t t-foreach="docs" t-as="o">
<t t-call="custom_picking_delivery_note_report.report_delivery_document" t-lang="o._get_report_lang()"/>
</t>
</template>

<template id="report_delivery_document" inherit_id="stock.report_delivery_document" primary="True">
<xpath expr="//table[@name='stock_move_table']/tbody" position="replace">
<tbody>
<t t-set="lines" t-value="o.move_ids.filtered(lambda x: x.product_uom_qty)"/>

<tr t-foreach="lines" t-as="move">
<t t-if="move.bom_line_id.bom_id.type != 'phantom'"> <!-- !condition to not print KITS for MO Delivery note -->
ksar-odoo marked this conversation as resolved.
Show resolved Hide resolved
<td>
<span t-field="move.product_id">Customizable Desk</span>
<p t-if="move.description_picking and move.description_picking != move.product_id.name and move.description_picking != move.product_id.display_name">
<span t-field="move.description_picking">Description on transfer</span>
</p>
</td>
<td class="text-end">
<span t-field="move.product_uom_qty">3.00</span>
<span t-field="move.product_uom" groups="uom.group_uom">units</span>
<span t-if="move.product_packaging_id">
(<span t-field="move.product_packaging_qty" t-options='{"widget": "integer"}'/> <span t-field="move.product_packaging_id"/>)
</span>
</td>
<td class="text-end">
<span t-field="move.quantity">3.00</span>
<span t-field="move.product_uom" groups="uom.group_uom">units</span>
<span t-if="move.product_packaging_id">
(<span t-field="move.product_packaging_quantity" t-options='{"widget": "integer"}'/> <span t-field="move.product_packaging_id"/>)
</span>
</td>
</t>
</tr>
</tbody>
</xpath>
</template>

</odoo>
2 changes: 2 additions & 0 deletions sell_product_kit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizard
16 changes: 16 additions & 0 deletions sell_product_kit/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
'name': 'Sell Product Kit',
'description': "Module to add function to sell product as a kit.",
'installable': True,
'application': False,
'depends': ['product', 'sale', 'sale_management'],
'data': [
'security/ir.model.access.csv',
'views/product_template_form_view_inherited.xml',
'wizard/product_kit_view_wizard.xml',
'views/view_order_form_inherited.xml',
'report/sale_order_document_report.xml',
'report/sale_portal_templates_report.xml'
],
'license':'LGPL-3'
}
3 changes: 3 additions & 0 deletions sell_product_kit/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import product_template
from . import sale_order_line
from . import sale_order
8 changes: 8 additions & 0 deletions sell_product_kit/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from odoo import fields, models


class InheritedProductTemplate(models.Model):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GLOBAL REMARK: we can keep the class name same as base class 🙂

Suggested change
class InheritedProductTemplate(models.Model):
class ProductTemplate(models.Model):

_inherit = "product.template"

is_kit = fields.Boolean(string="Is Kit", default=False)
sub_products_ids = fields.Many2many(comodel_name="product.product", string="Sub Products")
6 changes: 6 additions & 0 deletions sell_product_kit/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from odoo import models, fields

class SaleOrder(models.Model):
_inherit='sale.order'

print_in_report=fields.Boolean(string="Print in report?")
50 changes: 50 additions & 0 deletions sell_product_kit/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from odoo import fields, models, api

class InheritedProductTemplate(models.Model):
_inherit= "sale.order.line"

is_kit_product = fields.Boolean(
string="Is the product is a kit?",
related='product_template_id.is_kit',
depends=['product_id']
)

prev_filled_unit_price=fields.Float()

linked_product_kit_id = fields.Many2one(
string="Linked product kit Line",
comodel_name='sale.order.line',
ondelete='cascade',
domain="[('order_id', '=', order_id)]",
copy=False,
index=True,
)
linked_product_kit_ids = fields.One2many(
string="Linked product kit Lines", comodel_name='sale.order.line', inverse_name='linked_product_kit_id',
)
Comment on lines +14 to +24

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
linked_product_kit_id = fields.Many2one(
string="Linked product kit Line",
comodel_name='sale.order.line',
ondelete='cascade',
domain="[('order_id', '=', order_id)]",
copy=False,
index=True,
)
linked_product_kit_ids = fields.One2many(
string="Linked product kit Lines", comodel_name='sale.order.line', inverse_name='linked_product_kit_id',
)
product_kit_line_id = fields.Many2one(
string="Linked product kit Line",
comodel_name='sale.order.line',
ondelete='cascade',
domain="[('order_id', '=', order_id)]",
copy=False,
index=True,
)
child_product_line_ids = fields.One2many(
string="Child product Lines", comodel_name='sale.order.line', inverse_name='product_kit_line_id',
)

Name should be easier to read
Update all reference for the same


is_sub_line= fields.Boolean(
default=False,
compute="_compute_is_sub_line",
store=True
ksar-odoo marked this conversation as resolved.
Show resolved Hide resolved
)

@api.depends('linked_product_kit_id')
def _compute_is_sub_line(self):
for record in self:
if(record.linked_product_kit_id):
record.is_sub_line= True

def action_open_add_kit_wizard(self):
return {
'type' : 'ir.actions.act_window',
'name' : f'Product: {self.product_id.name}',
'res_model' : 'product.kit',
'view_type' : 'form',
'view_mode' : 'form',
'target' : 'new',
'context': {
'product_template_id': self.product_template_id.id,
'sale_order_line_id': self.id
}
}
11 changes: 11 additions & 0 deletions sell_product_kit/report/sale_order_document_report.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!--report to show sublines while clicking on setting>print/Quatation-order button in QO-->
<template id="sale_order_document_report_inherited" inherit_id="sale.report_saleorder_document">
<xpath expr="//tbody/t/tr" position="attributes">
<attribute name="t-if">(doc.print_in_report) or (not line.is_sub_line)</attribute>
<!-- do not show kit product kit sub lines-->
</xpath>
</template>

</odoo>
11 changes: 11 additions & 0 deletions sell_product_kit/report/sale_portal_templates_report.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!--report whether to show sublines while clicking on preview button in QO-->
<template id="sale_portal_templates_report_inherited" inherit_id="sale.sale_order_portal_content">
<xpath expr="//table[@id='sales_order_table']/tbody/t/tr" position="attributes">
<attribute name="t-if">(sale_order.print_in_report) or (not line.is_sub_line)</attribute>
<!-- do not show kit product kit sub lines-->
</xpath>
</template>

</odoo>
3 changes: 3 additions & 0 deletions sell_product_kit/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_product_kit,access_product_kit,model_product_kit,base.group_user,1,1,1,1
access_product_kit_lines,access_product_kit_lines,model_product_kit_lines,base.group_user,1,1,1,1
17 changes: 17 additions & 0 deletions sell_product_kit/views/product_template_form_view_inherited.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="product_template_form_view_inherited" model="ir.ui.view">
<field name="name">inherited.product.kit.view.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>

<field name="arch" type="xml">
<xpath expr="//group[@name='group_general']" position="inside">
<field name="is_kit"/>
<field name="sub_products_ids" widget="many2many_tags" invisible="not is_kit"/>
</xpath>
</field>
</record>

</odoo>
24 changes: 24 additions & 0 deletions sell_product_kit/views/view_order_form_inherited.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="view_order_form_inherited" model="ir.ui.view">
<field name="name">inherited.sale.order.view.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>

<field name="arch" type="xml">
<xpath expr="//field[@name='product_template_id']" position="after">
<button name="action_open_add_kit_wizard" type="object" class="btn-secondary" string="Add/Update Kit" invisible="not is_kit_product or state in ('sale')"/>
</xpath>

<xpath expr="//field[@name='order_line']/list" position="attributes">
<attribute name="decoration-muted">is_sub_line</attribute>
</xpath>

<xpath expr="//field[@name='payment_term_id']" position="after">
<field name="print_in_report"/>
</xpath>
</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions sell_product_kit/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import product_kit_model
96 changes: 96 additions & 0 deletions sell_product_kit/wizard/product_kit_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
from odoo import models, fields, api

class ProductKit(models.TransientModel):
_name="product.kit"

product_kit_line_ids= fields.One2many(comodel_name='product.kit.lines', inverse_name="product_kit_id")

@api.model
def default_get(self, fields_list):
product_template= self.env['product.template'].browse(self.env.context.get('product_template_id'))
sale_order_line_id = self.env['sale.order.line'].browse(self.env.context.get('sale_order_line_id'))

defaults = super().default_get(fields_list)
product_kit_line_ids={}

#Handling subproduct added later case in future case for that Taking union of existing and not existing line()
for c_pro in sale_order_line_id.linked_product_kit_ids:
product_kit_line_ids[c_pro.product_id.id]= {
'product_id':c_pro.product_id.id,
'quantity': c_pro.product_uom_qty,
'price': c_pro.prev_filled_unit_price
}
# is_kit_line_exits[c_pro.product_id.id]=True
for c_pro in product_template.sub_products_ids:
if(c_pro.id not in product_kit_line_ids.keys()):
product_kit_line_ids[c_pro.id]= {
'product_id': c_pro.id,
'quantity': 1,
'price': 0
}

defaults['product_kit_line_ids'] = self.env['product.kit.lines'].create(list(product_kit_line_ids.values()))
return defaults

#adding Sale kit product into sale order line
def action_add_kit_values_to_product(self):
sale_order_line= self.env['sale.order.line'].search([('id','=',self.env.context.get('active_id'))])

sub_product_total= 0

#is no sale.order.line exist related to the current product order line only then create else update
if(len(sale_order_line.linked_product_kit_ids)==0):
for prod in self.product_kit_line_ids:
self.env['sale.order.line'].create({
'linked_product_kit_id': sale_order_line.id,
'order_id': sale_order_line.order_id.id,
'product_id': prod.product_id.id,
'product_uom_qty': prod.quantity,
'price_unit': 0,
'customer_lead':0,
'prev_filled_unit_price': prod.price
})
sub_product_total+= prod.quantity * prod.price

sale_order_line.update({
'price_subtotal': sale_order_line.price_subtotal+sub_product_total
})
else:
new_subtotal= sale_order_line.price_subtotal
#remove the old price and add new price;
# formula==> new_subtotal = new_subtotal - (old_qty*price_pu) + (new_qty*price_pu)
# to update the linked_kit_lines details for next time

old_price=0
for old_line in sale_order_line.linked_product_kit_ids:
old_price+= old_line.product_uom_qty * old_line.prev_filled_unit_price

incomming_price=0
for new_line in self.product_kit_line_ids:
incomming_price+= new_line.quantity * new_line.price

new_subtotal= new_subtotal - old_price + incomming_price

for old_line in sale_order_line.linked_product_kit_ids:
for new_line in self.product_kit_line_ids:
if(old_line.product_id.id == new_line.product_id.id):
old_line.update({
'prev_filled_unit_price': new_line.price,
'product_uom_qty': new_line.quantity,
'price_unit':0
})

sale_order_line.update({
'price_subtotal': new_subtotal
})

self.product_kit_line_ids.unlink()
return True

class ProductKitLines(models.TransientModel):
_name="product.kit.lines"

product_kit_id= fields.Many2one(comodel_name="product.kit")
product_id= fields.Many2one(string="product", comodel_name='product.product')
quantity= fields.Float(string="quantity")
price= fields.Float(string="price")
26 changes: 26 additions & 0 deletions sell_product_kit/wizard/product_kit_view_wizard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="product_kit_view_form" model="ir.ui.view">
<field name="name">product kit Form View</field>
<field name="model">product.kit</field>
<field name="arch" type="xml">
<form string="form_view">
<h4>SUB PRODUCTS</h4>
<field name="product_kit_line_ids" >
<list create="0" delete="0" editable="bottom">
<field name="product_id" readonly="1"></field>
<field name="quantity"></field>
<field name="price"></field>
</list>
</field>
<footer>
<button name="action_add_kit_values_to_product" string="Confirm" class='btn btn-primary' type="object"/>
<button special="cancel" string="Cancel"/>
</footer>
</form>

</field>

</record>

</odoo>