[MOV] purchase_mrp_subcontracting -> mrp_subcontracting_account
This commit is contained in:
@@ -11,12 +11,12 @@
|
||||
'depends': ['mrp'],
|
||||
'data': [
|
||||
'data/mrp_subcontracting_data.xml',
|
||||
'views/mrp_bom_views.xml',
|
||||
'views/res_partner_views.xml',
|
||||
'views/stock_warehouse_views.xml',
|
||||
'views/stock_move_views.xml',
|
||||
'views/stock_picking_views.xml',
|
||||
'views/res_partner_views.xml',
|
||||
'views/mrp_bom_views.xml',
|
||||
'views/res_partner_views.xml',
|
||||
'views/supplier_info_views.xml',
|
||||
],
|
||||
'demo': [
|
||||
'data/mrp_subcontracting_demo.xml',
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import mrp_bom
|
||||
from . import product
|
||||
from . import res_company
|
||||
from . import res_partner
|
||||
from . import stock_move
|
||||
|
||||
+3
-7
@@ -1,18 +1,14 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
|
||||
{
|
||||
'name': 'Purchase and Subcontracting Management',
|
||||
'name': 'Subcontracting Management with Stock Valuation',
|
||||
'version': '0.1',
|
||||
'category': 'Hidden',
|
||||
'description': """
|
||||
This bridge module allows to manage subcontracting with the purchase module.
|
||||
This bridge module allows to manage subcontracting with valuation.
|
||||
""",
|
||||
'depends': ['purchase_stock', 'mrp_subcontracting'],
|
||||
'data': [
|
||||
'views/supplier_info_views.xml',
|
||||
],
|
||||
'depends': ['mrp_subcontracting', 'mrp_account'],
|
||||
'installable': True,
|
||||
'auto_install': True,
|
||||
}
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import product
|
||||
from . import stock_picking
|
||||
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import models
|
||||
from odoo.osv.expression import OR
|
||||
|
||||
|
||||
class StockPicking(models.Model):
|
||||
_inherit = 'stock.picking'
|
||||
|
||||
def action_view_stock_valuation_layers(self):
|
||||
action = super(StockPicking, self).action_view_stock_valuation_layers()
|
||||
subcontracted_productions = self._get_subcontracted_productions()
|
||||
if not subcontracted_productions:
|
||||
return action
|
||||
domain = action['domain']
|
||||
domain_subcontracting = [('id', 'in', (subcontracted_productions.move_raw_ids | subcontracted_productions.move_finished_ids).stock_valuation_layer_ids.ids)]
|
||||
domain = OR([domain, domain_subcontracting])
|
||||
return dict(action, domain=domain)
|
||||
|
||||
def _prepare_subcontract_mo_vals(self, subcontract_move, bom):
|
||||
vals = super(StockPicking, self)._prepare_subcontract_mo_vals(subcontract_move, bom)
|
||||
if bom.product_tmpl_id.cost_method in ('fifo', 'average'):
|
||||
vals = dict(vals, extra_cost=subcontract_move._get_price_unit())
|
||||
return vals
|
||||
+1
-4
@@ -1,7 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import test_purchase_subcontracting
|
||||
|
||||
from . import test_subcontracting_account
|
||||
@@ -0,0 +1,58 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.addons.mrp_subcontracting.tests.common import TestMrpSubcontractingCommon
|
||||
from odoo.tests.common import Form
|
||||
|
||||
class TestAccountSubcontractingFlows(TestMrpSubcontractingCommon):
|
||||
def test_subcontracting_account_flow_1(self):
|
||||
self.stock_location = self.env.ref('stock.stock_location_stock')
|
||||
self.customer_location = self.env.ref('stock.stock_location_customers')
|
||||
self.supplier_location = self.env.ref('stock.stock_location_suppliers')
|
||||
self.uom_unit = self.env.ref('uom.product_uom_unit')
|
||||
self.env.ref('product.product_category_all').property_cost_method = 'fifo'
|
||||
|
||||
# IN 10@10 comp1 10@20 comp2
|
||||
move1 = self.env['stock.move'].create({
|
||||
'name': 'IN 10 units @ 10.00 per unit',
|
||||
'location_id': self.supplier_location.id,
|
||||
'location_dest_id': self.env.company.subcontracting_location_id.id,
|
||||
'product_id': self.comp1.id,
|
||||
'product_uom': self.uom_unit.id,
|
||||
'product_uom_qty': 10.0,
|
||||
'price_unit': 10.0,
|
||||
})
|
||||
move1._action_confirm()
|
||||
move1._action_assign()
|
||||
move1.move_line_ids.qty_done = 10.0
|
||||
move1._action_done()
|
||||
move2 = self.env['stock.move'].create({
|
||||
'name': 'IN 10 units @ 20.00 per unit',
|
||||
'location_id': self.supplier_location.id,
|
||||
'location_dest_id': self.env.company.subcontracting_location_id.id,
|
||||
'product_id': self.comp2.id,
|
||||
'product_uom': self.uom_unit.id,
|
||||
'product_uom_qty': 10.0,
|
||||
'price_unit': 20.0,
|
||||
})
|
||||
move2._action_confirm()
|
||||
move2._action_assign()
|
||||
move2.move_line_ids.qty_done = 10.0
|
||||
move2._action_done()
|
||||
|
||||
picking_form = Form(self.env['stock.picking'])
|
||||
picking_form.picking_type_id = self.env.ref('stock.picking_type_in')
|
||||
picking_form.partner_id = self.subcontractor_partner1
|
||||
with picking_form.move_ids_without_package.new() as move:
|
||||
move.product_id = self.finished
|
||||
move.product_uom_qty = 1
|
||||
picking_receipt = picking_form.save()
|
||||
picking_receipt.move_lines.price_unit = 30.0
|
||||
|
||||
picking_receipt.action_confirm()
|
||||
picking_receipt.move_lines.quantity_done = 1.0
|
||||
picking_receipt.action_done()
|
||||
|
||||
mo = picking_receipt._get_subcontracted_productions()
|
||||
self.assertEqual(mo.move_finished_ids.stock_valuation_layer_ids.value, 60)
|
||||
self.assertEqual(mo.move_finished_ids.product_id.value_svl, 60)
|
||||
@@ -1,37 +0,0 @@
|
||||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * purchase_mrp_subcontracting
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server saas~12.4\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2019-08-12 11:32+0000\n"
|
||||
"PO-Revision-Date: 2019-08-12 11:32+0000\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: \n"
|
||||
"Plural-Forms: \n"
|
||||
|
||||
#. module: purchase_mrp_subcontracting
|
||||
#: model:ir.model.fields,help:purchase_mrp_subcontracting.field_product_supplierinfo__is_subcontractor
|
||||
msgid ""
|
||||
"Choose a vendor of type subcontractor if you want to subcontract the product"
|
||||
msgstr ""
|
||||
|
||||
#. module: purchase_mrp_subcontracting
|
||||
#: model:ir.model.fields,field_description:purchase_mrp_subcontracting.field_product_supplierinfo__is_subcontractor
|
||||
msgid "Subcontracted"
|
||||
msgstr ""
|
||||
|
||||
#. module: purchase_mrp_subcontracting
|
||||
#: model:ir.model,name:purchase_mrp_subcontracting.model_product_supplierinfo
|
||||
msgid "Supplier Pricelist"
|
||||
msgstr ""
|
||||
|
||||
#. module: purchase_mrp_subcontracting
|
||||
#: model:ir.model,name:purchase_mrp_subcontracting.model_stock_picking
|
||||
msgid "Transfer"
|
||||
msgstr ""
|
||||
@@ -1,16 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class StockPicking(models.Model):
|
||||
_inherit = 'stock.picking'
|
||||
|
||||
def _prepare_subcontract_mo_vals(self, subcontract_move, bom):
|
||||
vals = super(StockPicking, self)._prepare_subcontract_mo_vals(subcontract_move, bom)
|
||||
if bom.product_tmpl_id.cost_method in ('fifo', 'average'):
|
||||
vals = dict(vals, extra_cost=subcontract_move._get_price_unit())
|
||||
return vals
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from odoo.tests import Form
|
||||
from odoo.tests.common import TransactionCase
|
||||
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
|
||||
|
||||
|
||||
class TestPurchaseSubcontractingFlows(TransactionCase):
|
||||
def setUp(self):
|
||||
super(TestPurchaseSubcontractingFlows, self).setUp()
|
||||
|
||||
# 1. Create a BOM of subcontracting type
|
||||
self.comp1 = self.env['product.product'].create({
|
||||
'name': 'Component1',
|
||||
'type': 'product',
|
||||
'categ_id': self.env.ref('product.product_category_all').id,
|
||||
})
|
||||
self.comp2 = self.env['product.product'].create({
|
||||
'name': 'Component2',
|
||||
'type': 'product',
|
||||
'categ_id': self.env.ref('product.product_category_all').id,
|
||||
})
|
||||
self.finished_product = self.env['product.product'].create({
|
||||
'name': 'finished',
|
||||
'type': 'product',
|
||||
'categ_id': self.env.ref('product.product_category_all').id,
|
||||
})
|
||||
bom_form = Form(self.env['mrp.bom'])
|
||||
bom_form.type = 'subcontract'
|
||||
bom_form.product_tmpl_id = self.finished_product.product_tmpl_id
|
||||
with bom_form.bom_line_ids.new() as bom_line:
|
||||
bom_line.product_id = self.comp1
|
||||
bom_line.product_qty = 1
|
||||
with bom_form.bom_line_ids.new() as bom_line:
|
||||
bom_line.product_id = self.comp2
|
||||
bom_line.product_qty = 1
|
||||
self.bom_finished_product = bom_form.save()
|
||||
|
||||
# 2: Create a subcontracting partner
|
||||
company_partner = self.env['res.partner'].create({'name': 'main_partner', 'is_company': True})
|
||||
self.subcontractor_partner1 = self.env['res.partner'].create({
|
||||
'name': 'subcontractor_partner',
|
||||
'parent_id': company_partner.id,
|
||||
'company_id': self.env.ref('base.main_company').id
|
||||
})
|
||||
|
||||
self.stock_location = self.env.ref('stock.stock_location_stock')
|
||||
self.customer_location = self.env.ref('stock.stock_location_customers')
|
||||
self.supplier_location = self.env.ref('stock.stock_location_suppliers')
|
||||
self.uom_unit = self.env.ref('uom.product_uom_unit')
|
||||
|
||||
def test_purchase_1(self):
|
||||
self.env.ref('product.product_category_all').property_cost_method = 'fifo'
|
||||
|
||||
# IN 10@10 comp1 10@20 comp2
|
||||
move1 = self.env['stock.move'].create({
|
||||
'name': 'IN 10 units @ 10.00 per unit',
|
||||
'location_id': self.supplier_location.id,
|
||||
'location_dest_id': self.env.user.company_id.subcontracting_location_id.id,
|
||||
'product_id': self.comp1.id,
|
||||
'product_uom': self.uom_unit.id,
|
||||
'product_uom_qty': 10.0,
|
||||
'price_unit': 10.0,
|
||||
})
|
||||
move1._action_confirm()
|
||||
move1._action_assign()
|
||||
move1.move_line_ids.qty_done = 10.0
|
||||
move1._action_done()
|
||||
move1 = self.env['stock.move'].create({
|
||||
'name': 'IN 10 units @ 20.00 per unit',
|
||||
'location_id': self.supplier_location.id,
|
||||
'location_dest_id': self.env.user.company_id.subcontracting_location_id.id,
|
||||
'product_id': self.comp2.id,
|
||||
'product_uom': self.uom_unit.id,
|
||||
'product_uom_qty': 10.0,
|
||||
'price_unit': 20.0,
|
||||
})
|
||||
move1._action_confirm()
|
||||
move1._action_assign()
|
||||
move1.move_line_ids.qty_done = 10.0
|
||||
move1._action_done()
|
||||
|
||||
po1 = self.env['purchase.order'].create({
|
||||
'partner_id': self.subcontractor_partner1.id,
|
||||
'order_line': [
|
||||
(0, 0, {
|
||||
'name': self.finished_product.name,
|
||||
'product_id': self.finished_product.id,
|
||||
'product_qty': 1,
|
||||
'product_uom': self.finished_product.uom_po_id.id,
|
||||
'price_unit': 30.0,
|
||||
'date_planned': datetime.today().strftime(DEFAULT_SERVER_DATETIME_FORMAT),
|
||||
}),
|
||||
],
|
||||
})
|
||||
po1.button_confirm()
|
||||
|
||||
picking1 = po1.picking_ids[0]
|
||||
|
||||
# Check the created manufacturing order
|
||||
mo = self.env['mrp.production'].search([('bom_id', '=', self.bom_finished_product.id)])
|
||||
self.assertEqual(len(mo), 1)
|
||||
|
||||
move1 = picking1.move_lines[0]
|
||||
move1.quantity_done = 1
|
||||
picking1.button_validate()
|
||||
self.assertEqual(mo.move_finished_ids.stock_valuation_layer_ids.value, 60)
|
||||
self.assertEqual(mo.move_finished_ids.product_id.value_svl, 60)
|
||||
|
||||
Reference in New Issue
Block a user