diff --git a/product_cores/__manifest__.py b/product_cores/__manifest__.py index e18a9624..08b04f83 100755 --- a/product_cores/__manifest__.py +++ b/product_cores/__manifest__.py @@ -3,7 +3,7 @@ { 'name': 'Product Cores', 'author': 'Hibou Corp. ', - 'version': '13.0.1.0.0', + 'version': '13.0.1.0.1', 'category': 'Tools', 'license': 'OPL-1', 'summary': 'Charge customers core deposits.', @@ -13,7 +13,7 @@ Charge customers core deposits. 'website': 'https://hibou.io/', 'depends': [ 'sale_stock', - 'purchase', + 'purchase_stock', ], 'data': [ 'views/product_views.xml', diff --git a/product_cores/models/__init__.py b/product_cores/models/__init__.py index b29ef4f6..db72a159 100644 --- a/product_cores/models/__init__.py +++ b/product_cores/models/__init__.py @@ -1,5 +1,6 @@ # Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details. +from . import account from . import product from . import purchase from . import sale diff --git a/product_cores/models/account.py b/product_cores/models/account.py new file mode 100644 index 00000000..c2bc3d61 --- /dev/null +++ b/product_cores/models/account.py @@ -0,0 +1,41 @@ +# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details. + +from datetime import timedelta +from odoo import models + + +class AccountMove(models.Model): + _inherit = 'account.move' + + def post(self): + if self._context.get('move_reverse_cancel'): + return super(AccountMove, self).post() + self._product_core_set_date_maturity() + return super(AccountMove, self).post() + + def _product_core_set_date_maturity(self): + for move in self: + for line in move.invoice_line_ids.filtered(lambda l: l.product_id.core_ok and l.product_id.type == 'service'): + regular_date_maturity = line.date + timedelta(days=(line.product_id.product_core_validity or 0)) + if move.type in ('in_invoice', 'in_refund', 'in_receipt'): + # derive from purchase + if move.type == 'in_refund' and line.purchase_line_id: + # try to date from original + po_move_lines = self.search([('purchase_line_id', '=', line.purchase_line_id.id)]) + po_move_lines = po_move_lines.filtered(lambda l: l.move_id.type == 'in_invoice') + if po_move_lines: + line.date_maturity = po_move_lines[0].date_maturity or regular_date_maturity + else: + line.date_maturity = regular_date_maturity + else: + line.date_maturity = regular_date_maturity + elif move.type in ('out_invoice', 'out_refund', 'out_receipt'): + # derive from sale + if move.type == 'out_refund' and line.sale_line_ids: + other_move_lines = line.sale_line_ids.mapped('invoice_lines').filtered(lambda l: l.move_id.type == 'out_invoice') + if other_move_lines: + line.date_maturity = other_move_lines[0].date_maturity or regular_date_maturity + else: + line.date_maturity = regular_date_maturity + else: + line.date_maturity = regular_date_maturity diff --git a/product_cores/models/purchase.py b/product_cores/models/purchase.py index 8fef0a60..3f9673ae 100644 --- a/product_cores/models/purchase.py +++ b/product_cores/models/purchase.py @@ -34,7 +34,7 @@ class PurchaseOrderLine(models.Model): def write(self, values): res = super(PurchaseOrderLine, self).write(values) - if 'product_id' in values or 'product_qty' in values or 'product_uom' in values: + if any(f in values for f in ('product_id', 'product_qty', 'product_uom')): self.filtered(lambda l: not l.core_line_id)\ .mapped('order_id.order_line')\ .filtered('core_line_id')\ @@ -62,3 +62,9 @@ class PurchaseOrderLine(models.Model): }) elif line.core_line_id: line.unlink() + + @api.depends('qty_received_method', 'qty_received_manual', 'core_line_id.qty_received') + def _compute_qty_received(self): + super(PurchaseOrderLine, self)._compute_qty_received() + for line in self.filtered(lambda l: l.qty_received_method == 'manual' and l.core_line_id): + line.qty_received = line.core_line_id.qty_received diff --git a/product_cores/tests/test_product_cores.py b/product_cores/tests/test_product_cores.py index 41edf769..b2f2181e 100644 --- a/product_cores/tests/test_product_cores.py +++ b/product_cores/tests/test_product_cores.py @@ -43,7 +43,8 @@ class TestProductCores(common.TransactionCase): 'core_ok': True, 'service_type': 'manual', 'supplier_taxes_id': [(6, 0, [self.purchase_tax_service.id])], - 'taxes_id': [(6, 0, [self.sale_tax_service.id])] + 'taxes_id': [(6, 0, [self.sale_tax_service.id])], + 'product_core_validity': 30, }) self.product_core = self.env['product.product'].create({ 'name': 'Turbo Core', @@ -109,7 +110,14 @@ class TestProductCores(common.TransactionCase): purchase.button_confirm() self.assertEqual(purchase.state, 'purchase') self.assertEqual(len(purchase.picking_ids), 1) + self.assertEqual(len(purchase.picking_ids.move_line_ids), 1) # shouldn't have the service + purchase.picking_ids.move_line_ids.qty_done = purchase.picking_ids.move_line_ids.product_uom_qty purchase.picking_ids.button_validate() + purchase.flush() + + # All lines should be received on the PO + for line in purchase.order_line: + self.assertEqual(line.product_qty, line.qty_received) # From purchase.tests.test_purchase_order_report in 13 f = Form(self.env['account.move'].with_context(default_type='in_invoice')) @@ -118,6 +126,12 @@ class TestProductCores(common.TransactionCase): vendor_bill = f.save() self.assertEqual(len(vendor_bill.invoice_line_ids), 2) vendor_bill.post() + for line in vendor_bill.invoice_line_ids: + pol = purchase.order_line.filtered(lambda l: l.product_id == line.product_id) + self.assertTrue(pol) + self.assertEqual(line.quantity, pol.product_qty) + if line.product_id.type == 'service': + self.assertNotEqual(line.date, line.date_maturity) purchase.flush() # Duplicate PO