Skip to content

Commit

Permalink
[14.0][MIG]fieldservice_stock_account_analytic: migrated to v14
Browse files Browse the repository at this point in the history
  • Loading branch information
vimalpatelserpentcs authored and Freni-OSI committed Nov 14, 2022
1 parent eecfd8a commit 63d9a69
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 33 deletions.
29 changes: 14 additions & 15 deletions fieldservice_stock_account_analytic/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# Copyright (C) 2019 Open Source Integrators
# Copyright (C) 2021 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Field Service - Stock - Analytic Accounting',
'summary': 'Track costs of delivered items with analytic accounting',
'license': 'AGPL-3',
'version': '12.0.1.1.0',
'category': 'Field Service',
'author': "Open Source Integrators, "
"Odoo Community Association (OCA)",
'website': 'https://github.com/OCA/field-service',
'depends': [
'fieldservice_account_analytic',
'fieldservice_stock_account',
'stock_request_analytic',
"name": "Field Service - Stock - Analytic Accounting",
"summary": "Track costs of delivered items with analytic accounting",
"license": "AGPL-3",
"version": "14.0.1.0.0",
"category": "Field Service",
"author": "Open Source Integrators, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/field-service",
"depends": [
"fieldservice_account_analytic",
"fieldservice_stock_account",
"stock_request_analytic",
],
'development_status': 'Beta',
'maintainers': ['max3903'],
"development_status": "Beta",
"maintainers": ["max3903"],
}
2 changes: 1 addition & 1 deletion fieldservice_stock_account_analytic/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2019 Open Source Integrators
# Copyright (C) 2021 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import stock_request
Expand Down
18 changes: 9 additions & 9 deletions fieldservice_stock_account_analytic/models/fsm_order.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Copyright (C) 2019 Open Source Integrators
# Copyright (C) 2021 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class FSMOrder(models.Model):
_inherit = 'fsm.order'
_inherit = "fsm.order"

def _prepare_inv_line_for_stock_request(self, stock_request,
invoice=False):
vals = super()._prepare_inv_line_for_stock_request(
stock_request, invoice)
vals.update({
'analytic_account_id': self.location_id.analytic_account_id.id,
})
def _prepare_inv_line_for_stock_request(self, stock_request, invoice=False):
vals = super()._prepare_inv_line_for_stock_request(stock_request, invoice)
vals.update(
{
"analytic_account_id": self.location_id.analytic_account_id.id,
}
)
return vals
15 changes: 7 additions & 8 deletions fieldservice_stock_account_analytic/models/stock_request.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# Copyright (C) 2019 Open Source Integrators
# Copyright (C) 2021 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models


class StockRequest(models.Model):
_inherit = 'stock.request'
_inherit = "stock.request"

@api.model
def create(self, vals):
if 'fsm_order_id' in vals and vals.get('fsm_order_id'):
fsm_order = self.env['fsm.order'].browse(vals.get('fsm_order_id'))
vals.update({
'analytic_account_id':
fsm_order.location_id.analytic_account_id.id
})
if vals.get("fsm_order_id"):
fsm_order = self.env["fsm.order"].browse(vals.get("fsm_order_id"))
vals.update(
{"analytic_account_id": fsm_order.location_id.analytic_account_id.id}
)
return super().create(vals)
4 changes: 4 additions & 0 deletions fieldservice_stock_account_analytic/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (C) 2022 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from . import test_fsm_stock_account_analytic
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright (C) 2022 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

import datetime

from odoo.tests.common import TransactionCase


class FSMStockAccountAnalyticCase(TransactionCase):
def setUp(self):
super(FSMStockAccountAnalyticCase, self).setUp()
self.fsm_order = self.env["fsm.order"]
self.test_location = self.env.ref("fieldservice.test_location")
self.inv_location = self.env.ref("stock.stock_location_customers")
self.test_person = self.env.ref("fieldservice.test_person")
self.test_partner = self.env.ref("fieldservice.test_partner")
self.analytic_model = self.env["account.analytic.account"]
self.analytic = self.analytic_model.create({"name": "Test"})

def test_fsm_order(self):
self.test_person.partner_id.supplier_rank = 1
self.test_location.inventory_location_id = self.inv_location.id
self.test_location.analytic_account_id = self.analytic.id
fsm_order = self.fsm_order.create(
{"location_id": self.test_location.id, "person_id": self.test_person.id}
)

self.env["stock.picking.type"].create(
{
"name": "Stock Request wh",
"sequence_id": self.env.ref("stock_request.seq_stock_request_order").id,
"code": "stock_request_order",
"sequence_code": "SRO",
"warehouse_id": fsm_order.warehouse_id.id,
}
)
self.product_1 = self.env["product.product"].create(
{
"name": "Product 1",
"type": "product",
"categ_id": self.env.ref("product.product_category_all").id,
}
)
SR_1 = self.env["stock.request"].create(
{
"warehouse_id": fsm_order.warehouse_id.id,
"location_id": fsm_order.inventory_location_id.id,
"product_id": self.product_1.id,
"product_uom_qty": 1,
"product_uom_id": self.product_1.uom_id.id,
"fsm_order_id": fsm_order.id,
"direction": "outbound",
"expected_date": datetime.datetime.now(),
"picking_policy": "direct",
}
)
fsm_order.stock_request_ids = [(6, 0, SR_1.ids)]
fsm_order.action_request_submit()
SR_1.action_confirm()
fsm_order.account_create_invoice()

0 comments on commit 63d9a69

Please sign in to comment.