mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
Merge branch 'imp/13.0/product_cores__po_received_and_account_date_maturity' into '13.0'
imp/13.0/product_cores__po_received_and_account_date_maturity into 13.0 See merge request hibou-io/hibou-odoo/suite!519
This commit is contained in:
@@ -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.0',
|
'version': '13.0.1.0.1',
|
||||||
'category': 'Tools',
|
'category': 'Tools',
|
||||||
'license': 'OPL-1',
|
'license': 'OPL-1',
|
||||||
'summary': 'Charge customers core deposits.',
|
'summary': 'Charge customers core deposits.',
|
||||||
@@ -13,7 +13,7 @@ Charge customers core deposits.
|
|||||||
'website': 'https://hibou.io/',
|
'website': 'https://hibou.io/',
|
||||||
'depends': [
|
'depends': [
|
||||||
'sale_stock',
|
'sale_stock',
|
||||||
'purchase',
|
'purchase_stock',
|
||||||
],
|
],
|
||||||
'data': [
|
'data': [
|
||||||
'views/product_views.xml',
|
'views/product_views.xml',
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||||
|
|
||||||
|
from . import account
|
||||||
from . import product
|
from . import product
|
||||||
from . import purchase
|
from . import purchase
|
||||||
from . import sale
|
from . import sale
|
||||||
|
|||||||
41
product_cores/models/account.py
Normal file
41
product_cores/models/account.py
Normal file
@@ -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
|
||||||
@@ -34,7 +34,7 @@ class PurchaseOrderLine(models.Model):
|
|||||||
|
|
||||||
def write(self, values):
|
def write(self, values):
|
||||||
res = super(PurchaseOrderLine, self).write(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)\
|
self.filtered(lambda l: not l.core_line_id)\
|
||||||
.mapped('order_id.order_line')\
|
.mapped('order_id.order_line')\
|
||||||
.filtered('core_line_id')\
|
.filtered('core_line_id')\
|
||||||
@@ -62,3 +62,9 @@ class PurchaseOrderLine(models.Model):
|
|||||||
})
|
})
|
||||||
elif line.core_line_id:
|
elif line.core_line_id:
|
||||||
line.unlink()
|
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
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ class TestProductCores(common.TransactionCase):
|
|||||||
'core_ok': True,
|
'core_ok': True,
|
||||||
'service_type': 'manual',
|
'service_type': 'manual',
|
||||||
'supplier_taxes_id': [(6, 0, [self.purchase_tax_service.id])],
|
'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({
|
self.product_core = self.env['product.product'].create({
|
||||||
'name': 'Turbo Core',
|
'name': 'Turbo Core',
|
||||||
@@ -109,7 +110,14 @@ class TestProductCores(common.TransactionCase):
|
|||||||
purchase.button_confirm()
|
purchase.button_confirm()
|
||||||
self.assertEqual(purchase.state, 'purchase')
|
self.assertEqual(purchase.state, 'purchase')
|
||||||
self.assertEqual(len(purchase.picking_ids), 1)
|
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.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
|
# From purchase.tests.test_purchase_order_report in 13
|
||||||
f = Form(self.env['account.move'].with_context(default_type='in_invoice'))
|
f = Form(self.env['account.move'].with_context(default_type='in_invoice'))
|
||||||
@@ -118,6 +126,12 @@ class TestProductCores(common.TransactionCase):
|
|||||||
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.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()
|
purchase.flush()
|
||||||
|
|
||||||
# Duplicate PO
|
# Duplicate PO
|
||||||
|
|||||||
Reference in New Issue
Block a user