1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
|
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import odoo
from odoo.addons.point_of_sale.tests.common import TestPointOfSaleCommon
from odoo import fields
from odoo.tests import Form
@odoo.tests.tagged('post_install', '-at_install')
class TestPosMrp(TestPointOfSaleCommon):
def test_bom_kit_order_total_cost(self):
#create a product category that use fifo
category = self.env['product.category'].create({
'name': 'Category for kit',
'property_cost_method': 'fifo',
})
self.kit = self.env['product.product'].create({
'name': 'Kit Product',
'available_in_pos': True,
'is_storable': True,
'lst_price': 10.0,
'categ_id': category.id,
})
self.component_a = self.env['product.product'].create({
'name': 'Comp A',
'is_storable': True,
'available_in_pos': True,
'lst_price': 10.0,
'standard_price': 5.0,
})
self.component_b = self.env['product.product'].create({
'name': 'Comp B',
'is_storable': True,
'available_in_pos': True,
'lst_price': 10.0,
'standard_price': 10.0,
})
bom_product_form = Form(self.env['mrp.bom'])
bom_product_form.product_id = self.kit
bom_product_form.product_tmpl_id = self.kit.product_tmpl_id
bom_product_form.product_qty = 1.0
bom_product_form.type = 'phantom'
with bom_product_form.bom_line_ids.new() as bom_line:
bom_line.product_id = self.component_a
bom_line.product_qty = 1.0
with bom_product_form.bom_line_ids.new() as bom_line:
bom_line.product_id = self.component_b
bom_line.product_qty = 1.0
self.bom_a = bom_product_form.save()
self.pos_config.open_ui()
order = self.env['pos.order'].create({
'session_id': self.pos_config.current_session_id.id,
'lines': [(0, 0, {
'name': self.kit.name,
'product_id': self.kit.id,
'price_unit': self.kit.lst_price,
'qty': 1,
'tax_ids': [[6, False, []]],
'price_subtotal': self.kit.lst_price,
'price_subtotal_incl': self.kit.lst_price,
})],
'pricelist_id': self.pos_config.pricelist_id.id,
'amount_paid': self.kit.lst_price,
'amount_total': self.kit.lst_price,
'amount_tax': 0.0,
'amount_return': 0.0,
'to_invoice': False,
'last_order_preparation_change': '{}'
})
payment_context = {"active_ids": order.ids, "active_id": order.id}
order_payment = self.PosMakePayment.with_context(**payment_context).create({
'amount': order.amount_total,
'payment_method_id': self.cash_payment_method.id
})
order_payment.with_context(**payment_context).check()
self.pos_config.current_session_id.action_pos_session_closing_control()
pos_order = self.env['pos.order'].search([], order='id desc', limit=1)
self.assertEqual(pos_order.lines[0].total_cost, 15.0)
def test_bom_kit_with_kit_invoice_valuation(self):
# create a product category that use fifo
category = self.env['product.category'].create({
'name': 'Category for kit',
'property_cost_method': 'fifo',
'property_valuation': 'real_time',
})
self.kit = self.env['product.product'].create({
'name': 'Final Kit',
'available_in_pos': True,
'categ_id': category.id,
'taxes_id': False,
'is_storable': True,
})
self.kit_2 = self.env['product.product'].create({
'name': 'Final Kit 2',
'available_in_pos': True,
'categ_id': category.id,
'taxes_id': False,
'is_storable': True,
})
self.subkit1 = self.env['product.product'].create({
'name': 'Subkit 1',
'available_in_pos': True,
'categ_id': category.id,
'taxes_id': False,
})
self.subkit2 = self.env['product.product'].create({
'name': 'Subkit 2',
'available_in_pos': True,
'categ_id': category.id,
'taxes_id': False,
})
self.component_a = self.env['product.product'].create({
'name': 'Comp A',
'available_in_pos': True,
'standard_price': 5.0,
'categ_id': category.id,
'taxes_id': False,
})
self.component_b = self.env['product.product'].create({
'name': 'Comp B',
'available_in_pos': True,
'standard_price': 5.0,
'categ_id': category.id,
'taxes_id': False,
})
self.component_c = self.env['product.product'].create({
'name': 'Comp C',
'available_in_pos': True,
'standard_price': 5.0,
'categ_id': category.id,
'taxes_id': False,
})
bom_product_form = Form(self.env['mrp.bom'])
bom_product_form.product_id = self.subkit1
bom_product_form.product_tmpl_id = self.subkit1.product_tmpl_id
bom_product_form.product_qty = 1.0
bom_product_form.type = 'phantom'
with bom_product_form.bom_line_ids.new() as bom_line:
bom_line.product_id = self.component_a
bom_line.product_qty = 1.0
self.bom_a = bom_product_form.save()
bom_product_form = Form(self.env['mrp.bom'])
bom_product_form.product_id = self.subkit2
bom_product_form.product_tmpl_id = self.subkit2.product_tmpl_id
bom_product_form.product_qty = 1.0
bom_product_form.type = 'phantom'
with bom_product_form.bom_line_ids.new() as bom_line:
bom_line.product_id = self.component_b
bom_line.product_qty = 1.0
with bom_product_form.bom_line_ids.new() as bom_line:
bom_line.product_id = self.component_c
bom_line.product_qty = 1.0
self.bom_b = bom_product_form.save()
bom_product_form = Form(self.env['mrp.bom'])
bom_product_form.product_id = self.kit
bom_product_form.product_tmpl_id = self.kit.product_tmpl_id
bom_product_form.product_qty = 1.0
bom_product_form.type = 'phantom'
with bom_product_form.bom_line_ids.new() as bom_line:
bom_line.product_id = self.subkit1
bom_line.product_qty = 1.0
with bom_product_form.bom_line_ids.new() as bom_line:
bom_line.product_id = self.subkit2
bom_line.product_qty = 1.0
self.final_bom = bom_product_form.save()
bom_product_form = Form(self.env['mrp.bom'])
bom_product_form.product_id = self.kit_2
bom_product_form.product_tmpl_id = self.kit_2.product_tmpl_id
bom_product_form.product_qty = 1.0
bom_product_form.type = 'phantom'
with bom_product_form.bom_line_ids.new() as bom_line:
bom_line.product_id = self.subkit1
bom_line.product_qty = 2.0
with bom_product_form.bom_line_ids.new() as bom_line:
bom_line.product_id = self.subkit2
bom_line.product_qty = 3.0
self.final_bom = bom_product_form.save()
self.pos_config.open_ui()
order_data = {
'to_invoice': True,
'amount_paid': 2.0,
'amount_return': 0,
'amount_tax': 0,
'amount_total': 2.0,
'date_order': fields.Datetime.to_string(fields.Datetime.now()),
'fiscal_position_id': False,
'pricelist_id': self.pos_config.pricelist_id.id,
'lines': [[0, 0, {
'discount': 0,
'pack_lot_ids': [],
'price_unit': 2,
'product_id': self.kit.id,
'price_subtotal': 2,
'price_subtotal_incl': 2,
'qty': 1,
'tax_ids': [(6, 0, self.kit.taxes_id.ids)]}], [0, 0, {
'discount': 0,
'pack_lot_ids': [],
'price_unit': 2,
'product_id': self.kit_2.id,
'price_subtotal': 2,
'price_subtotal_incl': 2,
'qty': 1,
'tax_ids': [(6, 0, self.kit_2.taxes_id.ids)]}
]],
'name': 'Order 00042-003-0014',
'partner_id': self.partner1.id,
'session_id': self.pos_config.current_session_id.id,
'sequence_number': 2,
'payment_ids': [[0, 0, {
'amount': 2.0,
'name': fields.Datetime.now(),
'payment_method_id': self.cash_payment_method.id}
]],
'uuid': '00042-003-0014',
'user_id': self.env.uid
}
order = self.env['pos.order'].sync_from_ui([order_data])
order = self.env['pos.order'].browse(order['pos.order'][0]['id'])
self.assertEqual(order.lines.filtered(lambda l: l.product_id == self.kit).total_cost, 15.0)
accounts = self.kit.product_tmpl_id.get_product_accounts()
debit_interim_account = accounts['stock_output']
credit_expense_account = accounts['expense']
invoice_accounts = order.account_move.line_ids.mapped('account_id.id')
self.assertTrue(debit_interim_account.id in invoice_accounts)
self.assertTrue(credit_expense_account.id in invoice_accounts)
expense_line = order.account_move.line_ids.filtered(lambda l: l.account_id.id == credit_expense_account.id)
self.assertEqual(expense_line.filtered(lambda l: l.product_id == self.kit).credit, 0.0)
self.assertEqual(expense_line.filtered(lambda l: l.product_id == self.kit).debit, 15.0)
interim_line = order.account_move.line_ids.filtered(lambda l: l.account_id.id == debit_interim_account.id)
self.assertEqual(interim_line.filtered(lambda l: l.product_id == self.kit).credit, 15.0)
self.assertEqual(interim_line.filtered(lambda l: l.product_id == self.kit).debit, 0.0)
self.pos_config.current_session_id.action_pos_session_closing_control()
def test_bom_kit_different_uom_invoice_valuation(self):
"""This test make sure that when a kit is made of product using UoM A but the bom line uses UoM B
the price unit is correctly computed on the invoice lines.
"""
self.env.user.groups_id += self.env.ref('uom.group_uom')
category = self.env['product.category'].create({
'name': 'Category for kit',
'property_cost_method': 'fifo',
'property_valuation': 'real_time',
})
self.kit = self.env['product.product'].create({
'name': 'Final Kit',
'available_in_pos': True,
'categ_id': category.id,
'taxes_id': False,
'is_storable': True,
})
self.component_a = self.env['product.product'].create({
'name': 'Comp A',
'available_in_pos': True,
'standard_price': 12000.0,
'categ_id': category.id,
'taxes_id': False,
'uom_id': self.env.ref('uom.product_uom_dozen').id,
})
bom_product_form = Form(self.env['mrp.bom'])
bom_product_form.product_id = self.kit
bom_product_form.product_tmpl_id = self.kit.product_tmpl_id
bom_product_form.product_qty = 2.0
bom_product_form.type = 'phantom'
with bom_product_form.bom_line_ids.new() as bom_line:
bom_line.product_id = self.component_a
bom_line.product_qty = 6.0
bom_line.product_uom_id = self.env.ref('uom.product_uom_unit')
self.bom_a = bom_product_form.save()
self.pos_config.open_ui()
order_data = {'to_invoice': True,
'amount_paid': 2.0,
'amount_return': 0,
'amount_tax': 0,
'amount_total': 2.0,
'date_order': fields.Datetime.to_string(fields.Datetime.now()),
'fiscal_position_id': False,
'pricelist_id': self.pos_config.pricelist_id.id,
'lines': [[0,
0,
{'discount': 0,
'pack_lot_ids': [],
'price_unit': 2,
'product_id': self.kit.id,
'price_subtotal': 2,
'price_subtotal_incl': 2,
'qty': 2,
'tax_ids': []}],
],
'name': 'Order 00042-003-0014',
'partner_id': self.partner1.id,
'session_id': self.pos_config.current_session_id.id,
'sequence_number': 2,
'payment_ids': [[0,
0,
{'amount': 2.0,
'name': fields.Datetime.now(),
'payment_method_id': self.cash_payment_method.id}]],
'uuid': '00042-003-0014',
'user_id': self.env.uid}
order = self.env['pos.order'].sync_from_ui([order_data])
order = self.env['pos.order'].browse(order['pos.order'][0]['id'])
accounts = self.kit.product_tmpl_id.get_product_accounts()
expense_line = order.account_move.line_ids.filtered(lambda l: l.account_id.id == accounts['expense'].id)
self.assertEqual(expense_line.filtered(lambda l: l.product_id == self.kit).debit, 6000.0)
interim_line = order.account_move.line_ids.filtered(lambda l: l.account_id.id == accounts['stock_output'].id)
self.assertEqual(interim_line.filtered(lambda l: l.product_id == self.kit).credit, 6000.0)
|