feat(fusion_plating_jobs): multi-part cert creation + requirement union
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -10,3 +10,4 @@ from . import test_autopause_cron
|
||||
from . import test_post_shop_states
|
||||
from . import test_recipe_cert_suppression
|
||||
from . import test_order_ship_state
|
||||
from . import test_combined_cert_creation
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestCombinedCertCreation(TransactionCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.partner = self.env['res.partner'].create({
|
||||
'name': 'CertCust',
|
||||
'x_fc_send_coc': True, # drives the coc requirement
|
||||
})
|
||||
self.product = self.env['product.product'].create({'name': 'W'})
|
||||
self.part_a = self.env['fp.part.catalog'].create({
|
||||
'name': 'PartA', 'partner_id': self.partner.id, 'part_number': 'A-1'})
|
||||
self.part_b = self.env['fp.part.catalog'].create({
|
||||
'name': 'PartB', 'partner_id': self.partner.id, 'part_number': 'B-2'})
|
||||
self.so = self.env['sale.order'].create({
|
||||
'partner_id': self.partner.id,
|
||||
'order_line': [
|
||||
(0, 0, {'product_id': self.product.id, 'product_uom_qty': 3,
|
||||
'x_fc_part_catalog_id': self.part_a.id}),
|
||||
(0, 0, {'product_id': self.product.id, 'product_uom_qty': 2,
|
||||
'x_fc_part_catalog_id': self.part_b.id}),
|
||||
],
|
||||
})
|
||||
|
||||
def test_combined_cert_has_one_line_per_so_line(self):
|
||||
job = self.env['fp.job'].create({
|
||||
'partner_id': self.partner.id,
|
||||
'product_id': self.product.id,
|
||||
'qty': 5.0,
|
||||
'sale_order_id': self.so.id,
|
||||
'part_catalog_id': self.part_a.id,
|
||||
'sale_order_line_ids': [(6, 0, self.so.order_line.ids)],
|
||||
})
|
||||
job._fp_create_certificates()
|
||||
cert = self.env['fp.certificate'].search([('x_fc_job_id', '=', job.id)])
|
||||
self.assertEqual(len(cert), 1, 'one combined CoC')
|
||||
self.assertEqual(len(cert.part_line_ids), 2, 'one part-line per SO line')
|
||||
self.assertEqual(
|
||||
set(cert.part_line_ids.mapped('part_number')), {'A-1', 'B-2'})
|
||||
a = cert.part_line_ids.filtered(lambda p: p.part_number == 'A-1')
|
||||
self.assertEqual(a.quantity_shipped, 3, 'shipped qty from the line')
|
||||
|
||||
def test_part_lines_fall_back_to_so_order_line(self):
|
||||
# Job without an explicit sale_order_line_ids M2M still builds
|
||||
# one part-line per plating line via the SO order_line fallback.
|
||||
job = self.env['fp.job'].create({
|
||||
'partner_id': self.partner.id,
|
||||
'product_id': self.product.id,
|
||||
'qty': 5.0,
|
||||
'sale_order_id': self.so.id,
|
||||
'part_catalog_id': self.part_a.id,
|
||||
})
|
||||
job._fp_create_certificates()
|
||||
cert = self.env['fp.certificate'].search([('x_fc_job_id', '=', job.id)])
|
||||
self.assertEqual(len(cert), 1)
|
||||
self.assertEqual(len(cert.part_line_ids), 2,
|
||||
'falls back to SO order_line when no M2M lines set')
|
||||
Reference in New Issue
Block a user