mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[ADD] Business logic to add analytic lines on stock reservation.
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
"website": "https://github.com/OCA/manufacture",
|
||||
"license": "AGPL-3",
|
||||
"depends": ["mrp_analytic", "account"],
|
||||
"data": ["views/account_analytic_line_view.xml"],
|
||||
"data": ["views/account_analytic_line_view.xml", "views/mrp_production_views.xml"],
|
||||
"maintainer": "dreispt",
|
||||
"development_status": "Alpha",
|
||||
"installable": True,
|
||||
|
||||
@@ -2,3 +2,4 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import account_analytic_line
|
||||
from . import mrp_production
|
||||
|
||||
26
mrp_analytic_cost_material/models/mrp_production.py
Normal file
26
mrp_analytic_cost_material/models/mrp_production.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# Copyright (C) 2020 Open Source Integrators
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class MrpProduction(models.Model):
|
||||
_inherit = "mrp.production"
|
||||
|
||||
def generate_analytic_line(self):
|
||||
"""Generate Analytic Lines Manually."""
|
||||
for order in self:
|
||||
AccountAnalyticLine = self.env["account.analytic.line"].sudo()
|
||||
for line in order.move_raw_ids:
|
||||
line_vals = {
|
||||
"name": line.product_id.default_code or "",
|
||||
"account_id": order.analytic_account_id.id or False,
|
||||
"ref": order.name,
|
||||
"unit_amount": line.product_uom_qty,
|
||||
"company_id": order.company_id.id,
|
||||
"manufacturing_order_id": order.id,
|
||||
"product_id": line.product_id.id or False,
|
||||
"stock_move_id": line.raw_material_production_id.id,
|
||||
}
|
||||
analytic_line = AccountAnalyticLine.create(line_vals)
|
||||
analytic_line.on_change_unit_amount()
|
||||
18
mrp_analytic_cost_material/views/mrp_production_views.xml
Normal file
18
mrp_analytic_cost_material/views/mrp_production_views.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<record id="custom_mrp_production_form_view" model="ir.ui.view">
|
||||
<field name="name">custom.mrp.production.form</field>
|
||||
<field name="model">mrp.production</field>
|
||||
<field name="inherit_id" ref="mrp.mrp_production_form_view" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr='//button[@name="button_mark_done"]' position='before'>
|
||||
<button
|
||||
name="generate_analytic_line"
|
||||
class="btn-primary"
|
||||
type="object"
|
||||
string="Generate Analytic Items"
|
||||
/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user