[MIG] product_cores: to Odoo 14.0

This commit is contained in:
Jared Kipe
2021-12-03 10:24:38 -08:00
parent 2798b04643
commit bf5318710e
3 changed files with 18 additions and 17 deletions

View File

@@ -3,7 +3,7 @@
{ {
'name': 'Product Cores', 'name': 'Product Cores',
'author': 'Hibou Corp. <hello@hibou.io>', 'author': 'Hibou Corp. <hello@hibou.io>',
'version': '13.0.1.0.1', 'version': '14.0.1.0.0',
'category': 'Tools', 'category': 'Tools',
'license': 'OPL-1', 'license': 'OPL-1',
'summary': 'Charge customers core deposits.', 'summary': 'Charge customers core deposits.',

View File

@@ -7,32 +7,32 @@ from odoo import models
class AccountMove(models.Model): class AccountMove(models.Model):
_inherit = 'account.move' _inherit = 'account.move'
def post(self): def _post(self, soft=True):
if self._context.get('move_reverse_cancel'): if self._context.get('move_reverse_cancel'):
return super(AccountMove, self).post() return super(AccountMove, self)._post(soft)
self._product_core_set_date_maturity() self._product_core_set_date_maturity()
return super(AccountMove, self).post() return super(AccountMove, self)._post(soft)
def _product_core_set_date_maturity(self): def _product_core_set_date_maturity(self):
for move in 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'): 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)) 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'): if move.move_type in ('in_invoice', 'in_refund', 'in_receipt'):
# derive from purchase # derive from purchase
if move.type == 'in_refund' and line.purchase_line_id: if move.move_type == 'in_refund' and line.purchase_line_id:
# try to date from original # try to date from original
po_move_lines = self.search([('purchase_line_id', '=', line.purchase_line_id.id)]) 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') po_move_lines = po_move_lines.filtered(lambda l: l.move_id.move_type == 'in_invoice')
if po_move_lines: if po_move_lines:
line.date_maturity = po_move_lines[0].date_maturity or regular_date_maturity line.date_maturity = po_move_lines[0].date_maturity or regular_date_maturity
else: else:
line.date_maturity = regular_date_maturity line.date_maturity = regular_date_maturity
else: else:
line.date_maturity = regular_date_maturity line.date_maturity = regular_date_maturity
elif move.type in ('out_invoice', 'out_refund', 'out_receipt'): elif move.move_type in ('out_invoice', 'out_refund', 'out_receipt'):
# derive from sale # derive from sale
if move.type == 'out_refund' and line.sale_line_ids: if move.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') other_move_lines = line.sale_line_ids.mapped('invoice_lines').filtered(lambda l: l.move_id.move_type == 'out_invoice')
if other_move_lines: if other_move_lines:
line.date_maturity = other_move_lines[0].date_maturity or regular_date_maturity line.date_maturity = other_move_lines[0].date_maturity or regular_date_maturity
else: else:

View File

@@ -125,7 +125,7 @@ class TestProductCores(common.TransactionCase):
f.purchase_id = purchase f.purchase_id = purchase
vendor_bill = f.save() vendor_bill = f.save()
self.assertEqual(len(vendor_bill.invoice_line_ids), 2) self.assertEqual(len(vendor_bill.invoice_line_ids), 2)
vendor_bill.post() vendor_bill.action_post()
for line in vendor_bill.invoice_line_ids: for line in vendor_bill.invoice_line_ids:
pol = purchase.order_line.filtered(lambda l: l.product_id == line.product_id) pol = purchase.order_line.filtered(lambda l: l.product_id == line.product_id)
self.assertTrue(pol) self.assertTrue(pol)
@@ -209,9 +209,10 @@ class TestProductCores(common.TransactionCase):
sale.picking_ids.action_assign() sale.picking_ids.action_assign()
self.assertEqual(so_line.product_uom_qty, sale.picking_ids.move_lines.reserved_availability) self.assertEqual(so_line.product_uom_qty, sale.picking_ids.move_lines.reserved_availability)
res_dict = sale.picking_ids.button_validate() for move_line in sale.picking_ids.mapped('move_lines.move_line_ids'):
wizard = self.env[(res_dict.get('res_model'))].browse(res_dict.get('res_id')) move_line.qty_done = move_line.product_uom_qty
wizard.process() sale.picking_ids.button_validate()
self.assertEqual(sale.picking_ids.state, 'done')
self.assertEqual(so_line.qty_delivered, so_line.product_uom_qty) self.assertEqual(so_line.qty_delivered, so_line.product_uom_qty)
# Ensure all products are delivered. # Ensure all products are delivered.
@@ -243,8 +244,8 @@ class TestProductCores(common.TransactionCase):
return_picking = sale.picking_ids.filtered(lambda p: p.state != 'done') return_picking = sale.picking_ids.filtered(lambda p: p.state != 'done')
self.assertTrue(return_picking) self.assertTrue(return_picking)
res_dict = return_picking.button_validate() for move_line in return_picking.mapped('move_lines.move_line_ids'):
wizard = self.env[(res_dict.get('res_model'))].browse(res_dict.get('res_id')) move_line.qty_done = move_line.product_uom_qty
wizard.process() return_picking.button_validate()
self.assertTrue(all(l.qty_delivered == 0.0 for l in sale.order_line)) self.assertTrue(all(l.qty_delivered == 0.0 for l in sale.order_line))