[imp] add product and packaging page
This commit is contained in:
parent
140c30796a
commit
a35104c7f8
9 changed files with 143 additions and 33 deletions
20
.vscode/launch.json
vendored
20
.vscode/launch.json
vendored
|
|
@ -2,7 +2,7 @@
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "odoo-dev-16.0",
|
"name": "odoo-dev",
|
||||||
"type": "python",
|
"type": "python",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"cwd": "${workspaceRoot}",
|
"cwd": "${workspaceRoot}",
|
||||||
|
|
@ -17,6 +17,24 @@
|
||||||
// "--update=",
|
// "--update=",
|
||||||
"--dev=xml"
|
"--dev=xml"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "odoo-scratch",
|
||||||
|
"type": "python",
|
||||||
|
"request": "launch",
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"program": "${config:odoo.path}/odoo-bin",
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"args": [
|
||||||
|
"--database=odoo-scratch",
|
||||||
|
"--http-port=9069",
|
||||||
|
"--addons-path=${config:odoo.addons_path}",
|
||||||
|
"--limit-time-real=0",
|
||||||
|
"--limit-time-cpu=0",
|
||||||
|
"--init=sale_order_batch",
|
||||||
|
// "--update=",
|
||||||
|
"--dev=xml"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
"website": "https://www.bakeup.org",
|
"website": "https://www.bakeup.org",
|
||||||
"category": "Sale",
|
"category": "Sale",
|
||||||
"version": "16.0.0.0.1",
|
"version": "16.0.0.0.1",
|
||||||
"depends": ["sale"],
|
"depends": ["sale", "product"],
|
||||||
"data": [
|
"data": [
|
||||||
"data/ir_sequence_data.xml",
|
"data/ir_sequence_data.xml",
|
||||||
"views/sale_order_batch_views.xml",
|
"views/sale_order_batch_views.xml",
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
from . import product_product
|
||||||
from . import sale_order
|
from . import sale_order
|
||||||
from . import sale_order_batch
|
from . import sale_order_batch
|
||||||
from . import product_product
|
from . import sale_order_batch_product
|
||||||
|
from . import sale_order_line
|
||||||
|
|
|
||||||
|
|
@ -18,15 +18,16 @@ class SaleOrder(models.Model):
|
||||||
if not sale_order.batch_id and sale_order.state in ["draft", "sent"]:
|
if not sale_order.batch_id and sale_order.state in ["draft", "sent"]:
|
||||||
sale_order.batch_id = batch
|
sale_order.batch_id = batch
|
||||||
|
|
||||||
def write(self, vals):
|
def action_view_sale_order_batch(self):
|
||||||
if "batch_id" in vals:
|
return {
|
||||||
invalid_orders = []
|
"name": _("Sale Order Batch"),
|
||||||
for order in self:
|
"type": "ir.actions.act_window",
|
||||||
if order.state not in ["draft", "sent"]:
|
"view_type": "form",
|
||||||
invalid_orders.append(order.name)
|
"view_mode": "form",
|
||||||
if invalid_orders:
|
"res_model": "sale.order.batch",
|
||||||
raise UserError(_(f"Sale Order not in State Draft or Sent: {', '.join(invalid_orders)}"))
|
"res_id": self.batch_id.id,
|
||||||
return super().write(vals)
|
# 'target': '',
|
||||||
|
}
|
||||||
|
|
||||||
def action_confirm(self):
|
def action_confirm(self):
|
||||||
invalid_orders = []
|
invalid_orders = []
|
||||||
|
|
@ -38,13 +39,15 @@ class SaleOrder(models.Model):
|
||||||
raise UserError(_(f"Sale Order belongs to a Batch: {', '.join(invalid_orders)}"))
|
raise UserError(_(f"Sale Order belongs to a Batch: {', '.join(invalid_orders)}"))
|
||||||
return super().action_confirm()
|
return super().action_confirm()
|
||||||
|
|
||||||
def action_view_sale_order_batch(self):
|
def write(self, vals):
|
||||||
return {
|
if "batch_id" in vals:
|
||||||
"name": _("Sale Order Batch"),
|
invalid_orders = []
|
||||||
"type": "ir.actions.act_window",
|
for order in self:
|
||||||
"view_type": "form",
|
if order.state not in ["draft", "sent"]:
|
||||||
"view_mode": "form",
|
invalid_orders.append(order.name)
|
||||||
"res_model": "sale.order.batch",
|
if invalid_orders:
|
||||||
"res_id": self.batch_id.id,
|
raise UserError(_(f"Sale Order not in State Draft or Sent: {', '.join(invalid_orders)}"))
|
||||||
# 'target': '',
|
res = super().write(vals)
|
||||||
}
|
if "batch_id" in vals:
|
||||||
|
self.order_line._update_batch_products()
|
||||||
|
return res
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,11 @@ class SaleOrderBatch(models.Model):
|
||||||
_inherit = "mail.thread"
|
_inherit = "mail.thread"
|
||||||
_order = "date_order desc, id desc"
|
_order = "date_order desc, id desc"
|
||||||
|
|
||||||
|
# TODO: add company_id to sale order batch
|
||||||
|
# company_id = fields.Many2one(
|
||||||
|
# related='order_id.company_id',
|
||||||
|
# store=True, index=True, precompute=True)
|
||||||
|
|
||||||
name = fields.Char(
|
name = fields.Char(
|
||||||
string="Order Batch Reference",
|
string="Order Batch Reference",
|
||||||
required=True,
|
required=True,
|
||||||
|
|
@ -43,7 +48,7 @@ class SaleOrderBatch(models.Model):
|
||||||
sale_order_count = fields.Integer(compute="_compute_sale_order_count")
|
sale_order_count = fields.Integer(compute="_compute_sale_order_count")
|
||||||
sale_order_line_ids = fields.Many2many("sale.order.line", compute="_compute_sale_order_line_ids", store=True)
|
sale_order_line_ids = fields.Many2many("sale.order.line", compute="_compute_sale_order_line_ids", store=True)
|
||||||
amount_total = fields.Float(compute="_compute_amount_total", string="Total")
|
amount_total = fields.Float(compute="_compute_amount_total", string="Total")
|
||||||
product_ids = fields.Many2many("product.product", compute="_compute_product_ids")
|
product_ids = fields.One2many("sale.order.batch.product", "batch_id")
|
||||||
product_count = fields.Integer(compute="_compute_product_count")
|
product_count = fields.Integer(compute="_compute_product_count")
|
||||||
|
|
||||||
@api.depends("sale_order_ids.validity_date")
|
@api.depends("sale_order_ids.validity_date")
|
||||||
|
|
@ -59,15 +64,11 @@ class SaleOrderBatch(models.Model):
|
||||||
for batch in self:
|
for batch in self:
|
||||||
batch.sale_order_count = len(batch.sale_order_ids)
|
batch.sale_order_count = len(batch.sale_order_ids)
|
||||||
|
|
||||||
@api.depends("sale_order_ids.order_line")
|
|
||||||
def _compute_product_ids(self):
|
|
||||||
for sale_order in self:
|
|
||||||
sale_order.product_ids = sale_order.sale_order_ids.mapped("order_line").mapped("product_id")
|
|
||||||
|
|
||||||
@api.depends("sale_order_ids.order_line")
|
@api.depends("sale_order_ids.order_line")
|
||||||
def _compute_sale_order_line_ids(self):
|
def _compute_sale_order_line_ids(self):
|
||||||
for sale_order in self:
|
for batch in self:
|
||||||
sale_order.sale_order_line_ids = sale_order.sale_order_ids.mapped("order_line")
|
order_lines = self.env["sale.order.line"].search([("order_id", "in", batch.sale_order_ids.ids)])
|
||||||
|
batch.sale_order_line_ids = order_lines
|
||||||
|
|
||||||
@api.depends("sale_order_ids.amount_total")
|
@api.depends("sale_order_ids.amount_total")
|
||||||
def _compute_amount_total(self):
|
def _compute_amount_total(self):
|
||||||
|
|
|
||||||
46
sale_order_batch/models/sale_order_batch_product.py
Normal file
46
sale_order_batch/models/sale_order_batch_product.py
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
from odoo import api, fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class SaleOrderBatchProduct(models.Model):
|
||||||
|
"""Show Products available in Sale Order Batch"""
|
||||||
|
|
||||||
|
_name = "sale.order.batch.product"
|
||||||
|
_description = "Sale Order Batch Product"
|
||||||
|
|
||||||
|
batch_id = fields.Many2one(
|
||||||
|
comodel_name="sale.order.batch",
|
||||||
|
string="Batch Reference",
|
||||||
|
required=True,
|
||||||
|
ondelete="cascade",
|
||||||
|
index=True,
|
||||||
|
copy=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
product_id = fields.Many2one(comodel_name="product.product", required=True, readonly=False)
|
||||||
|
|
||||||
|
product_template_id = fields.Many2one(
|
||||||
|
"product.template", related="product_id.product_tmpl_id", string="Product Template"
|
||||||
|
)
|
||||||
|
sale_order_line_ids = fields.Many2many("sale.order.line", compute="_compute_sale_order_line_ids")
|
||||||
|
product_uom_category_id = fields.Many2one(related="product_id.uom_id.category_id", depends=["product_id"])
|
||||||
|
product_uom_qty = fields.Float(compute="_compute_uom_qty")
|
||||||
|
product_uom = fields.Many2one(related="product_id.uom_id")
|
||||||
|
product_packaging_id = fields.Many2one("product.packaging")
|
||||||
|
product_packaging_qty = fields.Float(compute="_compute_product_packaging_qty")
|
||||||
|
|
||||||
|
@api.depends("batch_id.sale_order_line_ids")
|
||||||
|
def _compute_sale_order_line_ids(self):
|
||||||
|
for product in self:
|
||||||
|
product.sale_order_line_ids = product.batch_id.sale_order_line_ids.filtered(
|
||||||
|
lambda o: o.product_id == product.product_id
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.depends("batch_id.sale_order_line_ids")
|
||||||
|
def _compute_uom_qty(self):
|
||||||
|
for product in self:
|
||||||
|
product.product_uom_qty = sum(product.sale_order_line_ids.mapped("product_uom_qty"))
|
||||||
|
|
||||||
|
@api.depends("product_packaging_id")
|
||||||
|
def _compute_product_packaging_qty(self):
|
||||||
|
for product in self:
|
||||||
|
product.product_packaging_qty = product.product_packaging_id.qty if product.product_packaging_id else 1
|
||||||
21
sale_order_batch/models/sale_order_line.py
Normal file
21
sale_order_batch/models/sale_order_line.py
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
from odoo import api, models
|
||||||
|
|
||||||
|
|
||||||
|
class SaleOrderLine(models.Model):
|
||||||
|
_inherit = "sale.order.line"
|
||||||
|
|
||||||
|
def _update_batch_products(self):
|
||||||
|
for order_line in self:
|
||||||
|
batch_id = order_line.order_id.batch_id
|
||||||
|
if batch_id:
|
||||||
|
registered_products = batch_id.mapped("product_ids").mapped("product_id")
|
||||||
|
if order_line.product_id not in registered_products:
|
||||||
|
self.env["sale.order.batch.product"].create(
|
||||||
|
{"batch_id": batch_id.id, "product_id": order_line.product_id.id}
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.model_create_multi
|
||||||
|
def create(self, vals_list):
|
||||||
|
res = super().create(vals_list)
|
||||||
|
res._update_batch_products()
|
||||||
|
return res
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||||
access_sale_order_batch,sale.order.batch,model_sale_order_batch,sales_team.group_sale_salesman,1,1,1,0
|
access_sale_order_batch,sale.order.batch,model_sale_order_batch,sales_team.group_sale_salesman,1,1,1,0
|
||||||
access_sale_order_batch_manager,sale.order.batch.manager,model_sale_order,sales_team.group_sale_manager,1,1,1,1
|
access_sale_order_batch_manager,sale.order.batch.manager,model_sale_order,sales_team.group_sale_manager,1,1,1,1
|
||||||
|
access_sale_order_batch_product,sale.order.batch.product,model_sale_order_batch_product,sales_team.group_sale_salesman,1,1,1,1
|
||||||
|
|
|
||||||
|
|
|
@ -70,11 +70,17 @@
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
<notebook>
|
<notebook>
|
||||||
<page string="Sale Order Lines" name="sale_order_line">
|
<page string="Sale Order Lines" name="order_line">
|
||||||
<field name="sale_order_line_ids">
|
<field
|
||||||
<tree>
|
name="sale_order_line_ids"
|
||||||
|
widget="section_and_note_one2many"
|
||||||
|
attrs="{'readonly': [('state', 'in', ('closed'))]}"
|
||||||
|
>
|
||||||
|
<tree editable="bottom">
|
||||||
|
<field name="sequence" widget="handle"/>
|
||||||
<field name="order_partner_id"/>
|
<field name="order_partner_id"/>
|
||||||
<field name="product_template_id"/>
|
<field name="product_template_id"/>
|
||||||
|
<field name="name"/>
|
||||||
<field name="product_uom_qty"/>
|
<field name="product_uom_qty"/>
|
||||||
<field name="price_unit"/>
|
<field name="price_unit"/>
|
||||||
<field name="price_subtotal"/>
|
<field name="price_subtotal"/>
|
||||||
|
|
@ -89,6 +95,18 @@
|
||||||
<div class="clearfix"/>
|
<div class="clearfix"/>
|
||||||
</group>
|
</group>
|
||||||
</page>
|
</page>
|
||||||
|
<page string="Products" name="products">
|
||||||
|
<field name="product_ids">
|
||||||
|
<tree create="0" editable="1">
|
||||||
|
<field name="product_template_id"/>
|
||||||
|
<field name="product_uom_category_id"/>
|
||||||
|
<field name="product_uom_qty"/>
|
||||||
|
<field name="product_uom"/>
|
||||||
|
<field name="product_packaging_id" groups="product.group_stock_packaging"/>
|
||||||
|
<field name="product_packaging_qty" groups="product.group_stock_packaging"/>
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
</page>
|
||||||
</notebook>
|
</notebook>
|
||||||
</sheet>
|
</sheet>
|
||||||
<div class="oe_chatter">
|
<div class="oe_chatter">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue