mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[14.0][IMP] stock_request_analytic: Add default analytic account on orders
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"),
|
||||
)
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user