[14.0][IMP] stock_request_analytic: Add default analytic account on orders

This commit is contained in:
Denis Roussel
2021-11-26 09:27:33 +01:00
parent 74a071cd8f
commit 353378aa28
5 changed files with 47 additions and 1 deletions

View File

@@ -2,7 +2,7 @@
# Copyright 2021 Tecnativa - João Marques
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import fields, models
from odoo import api, fields, models
class StockRequest(models.Model):
@@ -19,3 +19,13 @@ class StockRequest(models.Model):
string="Analytic Tags",
check_company=True,
)
@api.onchange("product_id")
def onchange_product_id(self):
"""
Set default analytic account on lines from order if defined.
"""
res = super().onchange_product_id()
if self.order_id and self.order_id.default_analytic_account_id:
self.analytic_account_id = self.order_id.default_analytic_account_id
return res

View File

@@ -35,6 +35,11 @@ class StockRequestOrder(models.Model):
string="Analytic Tags",
readonly=True,
)
default_analytic_account_id = fields.Many2one(
comodel_name="account.analytic.account",
string="Default Analytic Account",
help="Set this if you want to define a default analytic account on requests",
)
@api.depends("stock_request_ids")
def _compute_analytic_ids(self):

View File

@@ -1,6 +1,8 @@
* Aaron Henriquez <ahenriquez@eficent.com>
* Lois Rilo <lois.rilo@eficent.com>
* Pimolnat Suntian <pimolnats@ecosoft.co.th>
* Alan Ramos <alan.ramos@jarsa.com.mx>
* Denis Roussel <denis.roussel@acsone.eu>
* `Tecnativa <https://www.tecnativa.com>`__:
* João Marques

View File

@@ -3,6 +3,7 @@
from odoo import fields
from odoo.exceptions import UserError
from odoo.tests import Form
from odoo.addons.stock_request.tests import test_stock_request
@@ -148,3 +149,25 @@ class TestStockRequestAnalytic(test_stock_request.TestStockRequest):
self.analytic2, self.main_company
)
self.env["stock.request.order"].create(vals)
def test_default_analytic(self):
"""
Create request order with a default analytic
"""
vals = self.prepare_order_request_analytic(
self.analytic_model.browse(), self.main_company
)
vals.update(
{
"default_analytic_account_id": self.analytic.id,
}
)
order = self.env["stock.request.order"].create(vals)
with Form(order) as order_form:
with order_form.stock_request_ids.new() as line_form:
line_form.product_id = self.pizza
line_form.product_uom_qty = 5.0
self.assertEqual(
order.default_analytic_account_id,
order.stock_request_ids.mapped("analytic_account_id"),
)

View File

@@ -41,6 +41,12 @@
/>
</button>
</div>
<xpath expr="//field[@name='company_id']" position="after">
<field
name="default_analytic_account_id"
groups="analytic.group_analytic_accounting"
/>
</xpath>
<xpath
expr="//field[@name='stock_request_ids']/tree//field[@name='route_id']"
position="after"