new module reception_purchase_total
This commit is contained in:
parent
bb5b211d9c
commit
f615f8c960
6 changed files with 150 additions and 0 deletions
1
reception_purchase_total/__init__.py
Normal file
1
reception_purchase_total/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from . import models
|
||||
33
reception_purchase_total/__manifest__.py
Normal file
33
reception_purchase_total/__manifest__.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"name": "Reception Purchase Total",
|
||||
"version": "18.0.1.0.0",
|
||||
"category": "Inventory/Purchase",
|
||||
"summary": "Display purchase totals on stock reception views",
|
||||
"description": """
|
||||
This module adds purchase price totals to stock reception views. Specifically:
|
||||
|
||||
* Adds a total amount column to stock move lines in receptions, showing the purchase price * quantity
|
||||
* Shows a total amount at the bottom of operations and detailed operations tabs in:
|
||||
- Reception form view
|
||||
- Batch Transfer form view
|
||||
* Links stock moves to their original purchase order line prices
|
||||
|
||||
Technical Details:
|
||||
* Extends stock.move to compute total amount based on purchase line price
|
||||
* Adds computed fields and view inheritance to display totals
|
||||
* Compatible with standard Odoo purchase and inventory workflows
|
||||
""",
|
||||
"author": "Bemade Inc.",
|
||||
"website": "https://www.bemade.org",
|
||||
"depends": [
|
||||
"stock",
|
||||
"purchase_stock",
|
||||
],
|
||||
"data": [
|
||||
"views/stock_picking_views.xml",
|
||||
],
|
||||
"license": "LGPL-3",
|
||||
"installable": True,
|
||||
"auto_install": False,
|
||||
"application": False,
|
||||
}
|
||||
2
reception_purchase_total/models/__init__.py
Normal file
2
reception_purchase_total/models/__init__.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
from . import stock_move
|
||||
from . import stock_move_line
|
||||
32
reception_purchase_total/models/stock_move.py
Normal file
32
reception_purchase_total/models/stock_move.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class StockMove(models.Model):
|
||||
_inherit = "stock.move"
|
||||
|
||||
purchase_price_unit = fields.Float(
|
||||
string="Purchase Unit Price",
|
||||
related="purchase_line_id.price_unit",
|
||||
digits="Product Price",
|
||||
readonly=True,
|
||||
help="Unit price from the related purchase order line",
|
||||
)
|
||||
purchase_price_total = fields.Float(
|
||||
string="Purchase Total",
|
||||
compute="_compute_purchase_price_total",
|
||||
help="Total price based on purchase unit price and move quantity",
|
||||
)
|
||||
picking_type_code = fields.Selection(
|
||||
related="picking_id.picking_type_code",
|
||||
readonly=True,
|
||||
)
|
||||
purchase_currency_id = fields.Many2one(
|
||||
related="purchase_line_id.currency_id",
|
||||
string="Purchase Currency",
|
||||
readonly=True,
|
||||
)
|
||||
|
||||
@api.depends("purchase_price_unit", "quantity")
|
||||
def _compute_purchase_price_total(self):
|
||||
for move in self:
|
||||
move.purchase_price_total = move.purchase_price_unit * move.quantity
|
||||
34
reception_purchase_total/models/stock_move_line.py
Normal file
34
reception_purchase_total/models/stock_move_line.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
from odoo import fields, models, api
|
||||
|
||||
|
||||
class StockMoveLine(models.Model):
|
||||
_inherit = "stock.move.line"
|
||||
|
||||
picking_type_code = fields.Selection(
|
||||
related="picking_id.picking_type_id.code",
|
||||
string="Operation Type",
|
||||
store=True,
|
||||
readonly=True,
|
||||
)
|
||||
|
||||
purchase_price_unit = fields.Float(
|
||||
string="Purchase Unit Price",
|
||||
related="move_id.purchase_price_unit",
|
||||
readonly=True,
|
||||
help="Unit price from the related purchase order line",
|
||||
)
|
||||
purchase_price_total = fields.Float(
|
||||
string="Purchase Total",
|
||||
compute="_compute_purchase_price_total",
|
||||
help="Total price for this move line based on purchase price and quantity",
|
||||
)
|
||||
purchase_currency_id = fields.Many2one(
|
||||
related="move_id.purchase_currency_id",
|
||||
string="Purchase Currency",
|
||||
readonly=True,
|
||||
)
|
||||
|
||||
@api.depends("purchase_price_unit", "quantity")
|
||||
def _compute_purchase_price_total(self):
|
||||
for line in self:
|
||||
line.purchase_price_total = line.purchase_price_unit * line.quantity
|
||||
48
reception_purchase_total/views/stock_picking_views.xml
Normal file
48
reception_purchase_total/views/stock_picking_views.xml
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<!-- Stock Move List View for Batches -->
|
||||
<record id="view_move_tree_inherit_reception_purchase_total" model="ir.ui.view">
|
||||
<field name="name">stock.move.tree.inherit.reception.purchase.total</field>
|
||||
<field name="model">stock.move</field>
|
||||
<field name="inherit_id" ref="stock_picking_batch.view_picking_move_tree_inherited"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="product_uom" position="after">
|
||||
<field name="picking_type_code" invisible="1"/>
|
||||
<field name="purchase_currency_id" invisible="1"/>
|
||||
<field name="purchase_price_unit" optional="show" invisible="picking_type_code != 'incoming'" widget="monetary" options="{'currency_field': 'purchase_currency_id'}"/>
|
||||
<field name="purchase_price_total" optional="show" sum="Total Purchase Amount" invisible="picking_type_code != 'incoming'" widget="monetary" options="{'currency_field': 'purchase_currency_id'}"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Stock Move Line List View for Batches -->
|
||||
<record id="view_move_line_tree_inherit_reception_purchase_total" model="ir.ui.view">
|
||||
<field name="name">stock.move.line.tree.inherit.reception.purchase.total</field>
|
||||
<field name="model">stock.move.line</field>
|
||||
<field name="inherit_id" ref="stock_picking_batch.view_move_line_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="quantity" position="after">
|
||||
<field name="picking_type_code" invisible="1"/>
|
||||
<field name="purchase_currency_id" invisible="1"/>
|
||||
<field name="purchase_price_unit" optional="show" invisible="picking_type_code != 'incoming'" widget="monetary" options="{'currency_field': 'purchase_currency_id'}"/>
|
||||
<field name="purchase_price_total" optional="show" sum="Total Purchase Amount" invisible="picking_type_code != 'incoming'" widget="monetary" options="{'currency_field': 'purchase_currency_id'}"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Stock Picking Form View -->
|
||||
<record id="view_picking_form_inherit_reception_purchase_total" model="ir.ui.view">
|
||||
<field name="name">stock.picking.form.inherit.reception.purchase.total</field>
|
||||
<field name="model">stock.picking</field>
|
||||
<field name="inherit_id" ref="stock.view_picking_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<!-- Add total to operations tab -->
|
||||
<xpath expr="//page[@name='operations']//field[@name='move_ids_without_package']//list" position="inside">
|
||||
<field name="picking_type_code" invisible="1"/>
|
||||
<field name="purchase_currency_id" invisible="1"/>
|
||||
<field name="purchase_price_unit" optional="show" invisible="picking_type_code != 'incoming'" widget="monetary" options="{'currency_field': 'purchase_currency_id'}"/>
|
||||
<field name="purchase_price_total" optional="show" sum="Total Purchase Amount" invisible="picking_type_code != 'incoming'" widget="monetary" options="{'currency_field': 'purchase_currency_id'}"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Loading…
Reference in a new issue