diff --git a/crm_claim_rma/README.rst b/crm_claim_rma/README.rst index 744e83e8..2ae28b25 100644 --- a/crm_claim_rma/README.rst +++ b/crm_claim_rma/README.rst @@ -56,8 +56,6 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed feedback -`here `_. - Credits ======= @@ -74,6 +72,7 @@ Contributors: * Javier Carrasco * Yanina Aular * Osval Reyes +* Cyril Gaudin Maintainer ---------- diff --git a/crm_claim_rma/__init__.py b/crm_claim_rma/__init__.py index bbe8bffc..f553d8ff 100644 --- a/crm_claim_rma/__init__.py +++ b/crm_claim_rma/__init__.py @@ -1,28 +1,4 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright 2015 Vauxoo -# Copyright 2015 Eezee-It -# Copyright 2013 Camptocamp -# Copyright 2009-2013 Akretion, -# Author: Emmanuel Samyn, Raphaël Valyi, Sébastien Beau, -# Joel Grand-Guillaume -# Osval Reyes, Yanina Aular -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## from . import models from . import wizards diff --git a/crm_claim_rma/__openerp__.py b/crm_claim_rma/__openerp__.py index b04f50fb..469ab4a0 100644 --- a/crm_claim_rma/__openerp__.py +++ b/crm_claim_rma/__openerp__.py @@ -1,32 +1,12 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright 2015 Vauxoo -# Copyright 2015 Eezee-It -# Copyright 2013 Camptocamp -# Copyright 2009-2013 Akretion, -# Author: Emmanuel Samyn, Raphaël Valyi, Sébastien Beau, -# Benoît Guillot, Joel Grand-Guillaume, -# Osval Reyes, Yanina Aular -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2015 Vauxoo +# © 2015 Eezee-It +# © 2009-2013 Akretion +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'RMA Claim (Product Return Management)', - 'version': '8.0.1.1.1', + 'version': '9.0.1.0.0', 'category': 'Generic Modules/CRM & SRM', 'author': "Akretion, Camptocamp, Eezee-it, MONK Software, Vauxoo, " "Odoo Community Association (OCA)", @@ -45,8 +25,8 @@ ], 'data': [ 'data/ir_sequence_type.xml', - 'data/crm_case_section.xml', - 'data/crm_case_categ.xml', + 'data/crm_team.xml', + 'data/crm_claim_category.xml', 'views/account_invoice.xml', 'wizards/claim_make_picking.xml', 'views/crm_claim.xml', @@ -55,15 +35,10 @@ 'views/stock_view.xml', 'security/ir.model.access.csv', ], - 'demo': [ - 'demo/account_invoice.xml', - 'demo/account_invoice_line.xml', - 'demo/crm_claim.xml', - 'demo/claim_line.xml', - ], + 'demo': [], 'test': [ 'test/test_invoice_refund.yml' ], - 'installable': False, + 'installable': True, 'auto_install': False, } diff --git a/crm_claim_rma/data/crm_case_categ.xml b/crm_claim_rma/data/crm_case_categ.xml deleted file mode 100644 index d9f88745..00000000 --- a/crm_claim_rma/data/crm_case_categ.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - - - No Inventory - - - - - - Customer Return - - - - - - Buyer Cancelled - - - - - - General Adjustement - - - - - - Could Not Ship - - - - - - Different Item - - - - - - Merchandise Not Received - - - - - - Merchandise Not As Described - - - - - - Pricing Error - - - - - - Shipping Address Undeliverable - - - - - - Delivered Late by Carrier - - - - - - Missed Fulfilment Promise - - - - - diff --git a/crm_claim_rma/data/crm_case_section.xml b/crm_claim_rma/data/crm_case_section.xml deleted file mode 100644 index fea22f4d..00000000 --- a/crm_claim_rma/data/crm_case_section.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - After Sales Service - ASV - - - - diff --git a/crm_claim_rma/data/crm_claim_category.xml b/crm_claim_rma/data/crm_claim_category.xml new file mode 100644 index 00000000..99edccc1 --- /dev/null +++ b/crm_claim_rma/data/crm_claim_category.xml @@ -0,0 +1,62 @@ + + + + No Inventory + + + + + Customer Return + + + + + Buyer Cancelled + + + + + General Adjustement + + + + + Could Not Ship + + + + + Different Item + + + + + Merchandise Not Received + + + + + Merchandise Not As Described + + + + + Pricing Error + + + + + Shipping Address Undeliverable + + + + + Delivered Late by Carrier + + + + + Missed Fulfilment Promise + + + diff --git a/crm_claim_rma/data/crm_team.xml b/crm_claim_rma/data/crm_team.xml new file mode 100644 index 00000000..b5e2bce5 --- /dev/null +++ b/crm_claim_rma/data/crm_team.xml @@ -0,0 +1,7 @@ + + + + After Sales Service + ASV + + diff --git a/crm_claim_rma/data/ir_sequence_type.xml b/crm_claim_rma/data/ir_sequence_type.xml index 824e9b58..5171c29d 100644 --- a/crm_claim_rma/data/ir_sequence_type.xml +++ b/crm_claim_rma/data/ir_sequence_type.xml @@ -1,16 +1,9 @@ - - - - CRM Claim - crm.claim.rma - - - - CRM Claim - crm.claim.rma - - RMA-%(year)s/ - - - + + + CRM Claim + crm.claim.rma + + RMA-%(year)s/ + + diff --git a/crm_claim_rma/demo/account_invoice.xml b/crm_claim_rma/demo/account_invoice.xml deleted file mode 100644 index 70137484..00000000 --- a/crm_claim_rma/demo/account_invoice.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - draft - out_invoice - - - - - diff --git a/crm_claim_rma/demo/account_invoice_line.xml b/crm_claim_rma/demo/account_invoice_line.xml deleted file mode 100644 index 78e90ab6..00000000 --- a/crm_claim_rma/demo/account_invoice_line.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - iMac - 1799 - 3 - - - - - - - PC Assemble - 450 - 1 - - - diff --git a/crm_claim_rma/demo/claim_line.xml b/crm_claim_rma/demo/claim_line.xml deleted file mode 100644 index 01dffbdd..00000000 --- a/crm_claim_rma/demo/claim_line.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - Claim Line 1 of Claim 6 - - legal - - - 1 - 1799 - - 00013 - - - - Claim Line 2 of Claim 6 - - damaged - - - 1 - 450 - - 00012 - - - diff --git a/crm_claim_rma/demo/crm_claim.xml b/crm_claim_rma/demo/crm_claim.xml deleted file mode 100644 index d10a4d83..00000000 --- a/crm_claim_rma/demo/crm_claim.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/crm_claim_rma/models/__init__.py b/crm_claim_rma/models/__init__.py index a44e5bde..5527725b 100644 --- a/crm_claim_rma/models/__init__.py +++ b/crm_claim_rma/models/__init__.py @@ -1,27 +1,5 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright 2015 Vauxoo -# Copyright 2013 Camptocamp -# Copyright 2009-2013 Akretion, -# Author: Emmanuel Samyn, Raphaël Valyi, Sébastien Beau, -# Benoît Guillot, Joel Grand-Guillaume, -# Osval Reyes -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## + from . import account_invoice from . import account_invoice_line from . import claim_line diff --git a/crm_claim_rma/models/account_invoice.py b/crm_claim_rma/models/account_invoice.py index 116591a1..69c20834 100644 --- a/crm_claim_rma/models/account_invoice.py +++ b/crm_claim_rma/models/account_invoice.py @@ -1,27 +1,8 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright 2015 Eezee-It, MONK Software, Vauxoo -# Copyright 2013 Camptocamp -# Copyright 2009-2013 Akretion, -# Author: Emmanuel Samyn, Raphaël Valyi, Sébastien Beau, -# Benoît Guillot, Joel Grand-Guillaume, Leonardo Donelli -# Osval Reyes, Yanina Aular -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2015 Eezee-It, MONK Software, Vauxoo +# © 2013 Camptocamp +# © 2009-2013 Akretion, +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import _, api, exceptions, fields, models @@ -33,8 +14,7 @@ class AccountInvoice(models.Model): claim_id = fields.Many2one('crm.claim', string='Claim') def _refund_cleanup_lines(self, lines): - """ - Override when from claim to update the quantity and link to the + """ Override when from claim to update the quantity and link to the claim line. """ @@ -71,16 +51,14 @@ class AccountInvoice(models.Model): # TODO use custom states to show button of this wizard or # not instead of raise an error - raise exceptions.Warning( - _('A refund has already been created for this claim !')) + raise exceptions.UserError( + _('A refund has already been created for this claim !') + ) return [(0, 0, l) for l in new_lines] @api.model - def _prepare_refund(self, invoice, date=None, period_id=None, - description=None, journal_id=None): - result = super(AccountInvoice, self)._prepare_refund( - invoice, date=date, period_id=period_id, description=description, - journal_id=journal_id) + def _prepare_refund(self, *args, **kwargs): + result = super(AccountInvoice, self)._prepare_refund(*args, **kwargs) if self.env.context.get('claim_id'): result['claim_id'] = self.env.context['claim_id'] diff --git a/crm_claim_rma/models/account_invoice_line.py b/crm_claim_rma/models/account_invoice_line.py index eeb8aa9d..ea953c98 100644 --- a/crm_claim_rma/models/account_invoice_line.py +++ b/crm_claim_rma/models/account_invoice_line.py @@ -1,27 +1,9 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright 2015 Vauxoo -# Copyright 2013 Camptocamp -# Copyright 2009-2013 Akretion, -# Author: Emmanuel Samyn, Raphaël Valyi, Sébastien Beau, -# Benoît Guillot, Joel Grand-Guillaume, -# Osval Reyes, Yanina Aular -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2015 Vauxoo +# © 2013 Camptocamp +# © 2009-2013 Akretion, +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + from openerp import api, models diff --git a/crm_claim_rma/models/claim_line.py b/crm_claim_rma/models/claim_line.py index 2e8b6728..0a2331c7 100644 --- a/crm_claim_rma/models/claim_line.py +++ b/crm_claim_rma/models/claim_line.py @@ -1,27 +1,9 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright 2015 Vauxoo -# Copyright 2013 Camptocamp -# Copyright 2009-2013 Akretion, -# Author: Emmanuel Samyn, Raphaël Valyi, Sébastien Beau, -# Benoît Guillot, Joel Grand-Guillaume, -# Osval Reyes, Yanina Aular -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2015 Vauxoo +# © 2013 Camptocamp +# © 2009-2013 Akretion, +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + import calendar import math from datetime import datetime @@ -133,7 +115,9 @@ class ClaimLine(models.Model): @api.model def get_warranty_return_partner(self): - return self.env['product.supplierinfo'].get_warranty_return_partner() + return self.env['product.supplierinfo']._columns[ + 'warranty_return_partner' + ].selection warranty_type = fields.Selection( get_warranty_return_partner, readonly=True, @@ -304,12 +288,14 @@ class ClaimLine(models.Model): invoice_id, claim.claim_type, self.product_id, claim.date) except InvoiceNoDate: - raise exceptions.Warning( - _('Error'), _('Cannot find any date for invoice. ' - 'Must be a validated invoice.')) + raise exceptions.UserError( + _('Cannot find any date for invoice. ' + 'Must be a validated invoice.') + ) except ProductNoSupplier: - raise exceptions.Warning( - _('Error'), _('The product has no supplier configured.')) + raise exceptions.UserError( + _('The product has no supplier configured.') + ) self.write(values) return True @@ -326,8 +312,7 @@ class ClaimLine(models.Model): @api.returns('stock.location') def get_destination_location(self, product_id, warehouse_id): - """ - Compute and return the destination location to take + """ Compute and return the destination location to take for a return. Always take 'Supplier' one when return type different from company. """ @@ -343,8 +328,7 @@ class ClaimLine(models.Model): return location_dest_id def _warranty_return_address_values(self, product, company, warehouse): - """ - Return the partner to be used as return destination and + """ Return the partner to be used as return destination and the destination stock location of the line in case of return. We can have various cases here: @@ -386,33 +370,28 @@ class ClaimLine(models.Model): @api.multi def set_warranty(self): - """ - Calculate warranty limit and address + """ Calculate warranty limit and address """ for line_id in self: if not line_id.product_id: - raise exceptions.Warning( - _('Error'), _('Please set product first')) + raise exceptions.UserError(_('Please set product first')) if not line_id.invoice_line_id: - raise exceptions.Warning( - _('Error'), _('Please set invoice first')) + raise exceptions.UserError(_('Please set invoice first')) line_id.set_warranty_limit() line_id.set_warranty_return_address() @api.model def _get_sequence_number(self): - """ - @return the value of the sequence for the number field in the + """ Return the value of the sequence for the number field in the claim.line model. """ - return self.env['ir.sequence'].get('claim.line') + return self.env['ir.sequence'].next_by_code('claim.line') @api.model def create(self, vals): - """ - @return write the identify number once the claim line is create. + """Return write the identify number once the claim line is create. """ vals = vals or {} diff --git a/crm_claim_rma/models/crm_claim.py b/crm_claim_rma/models/crm_claim.py index 64be490d..b8f71204 100644 --- a/crm_claim_rma/models/crm_claim.py +++ b/crm_claim_rma/models/crm_claim.py @@ -1,27 +1,9 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright 2015 Eezee-It, MONK Software, Vauxoo -# Copyright 2013 Camptocamp -# Copyright 2009-2013 Akretion, -# Author: Emmanuel Samyn, Raphaël Valyi, Sébastien Beau, -# Benoît Guillot, Joel Grand-Guillaume, Leonardo Donelli, -# Osval Reyes, Yanina Aular -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2015 Eezee-It, MONK Software, Vauxoo +# © 2013 Camptocamp +# © 2009-2013 Akretion, +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + from openerp import _, api, exceptions, fields, models from .invoice_no_date import InvoiceNoDate @@ -36,8 +18,9 @@ class CrmClaim(models.Model): wh_obj = self.env['stock.warehouse'] wh = wh_obj.search([('company_id', '=', company_id)], limit=1) if not wh: - raise exceptions.Warning( - _('There is no warehouse for the current user\'s company.')) + raise exceptions.UserError( + _('There is no warehouse for the current user\'s company.') + ) return wh def _get_picking_ids(self): @@ -95,8 +78,7 @@ class CrmClaim(models.Model): @api.model def _get_claim_type_default(self): - claim_type = self.env['crm.claim.type'].search([]) - return claim_type[0] if claim_type else self.env['crm.claim.type'] + return self.env.ref('crm_claim_type.crm_claim_type_customer') claim_type = \ fields.Many2one(default=_get_claim_type_default, @@ -107,7 +89,6 @@ class CrmClaim(models.Model): def _onchange_invoice_warehouse_type_date(self): context = self.env.context claim_line = self.env['claim.line'] - invoice_lines = self.invoice_id.invoice_line if not self.warehouse_id: self.warehouse_id = self._get_default_warehouse() claim_type = self.claim_type @@ -135,7 +116,7 @@ class CrmClaim(models.Model): if create_lines: # happens when the invoice is changed claim_lines = [] - for invoice_line in invoice_lines: + for invoice_line in self.invoice_id.invoice_line_ids: location_dest = claim_line.get_destination_location( invoice_line.product_id, warehouse) line = { @@ -160,11 +141,19 @@ class CrmClaim(models.Model): self.delivery_address_id = self.invoice_id.partner_id.id @api.model - def message_get_reply_to(self): - """ Override to get the reply_to of the parent project. """ - return [claim.section_id.message_get_reply_to()[0] - if claim.section_id else False - for claim in self.sudo()] + def message_get_reply_to(self, res_ids, default=None): + """ Override to get the reply_to of the parent project. + """ + results = dict.fromkeys(res_ids, default or False) + if res_ids: + claims = self.browse(res_ids) + results.update({ + claim.id: self.env['crm.team'].message_get_reply_to( + [claim.team_id], default + )[claim.team_id] for claim in claims if claim.team_id + }) + + return results @api.multi def message_get_suggested_recipients(self): @@ -172,13 +161,17 @@ class CrmClaim(models.Model): try: for claim in self: if claim.partner_id: - self._message_add_suggested_recipient( - recipients, claim, - partner=claim.partner_id, reason=_('Customer')) + claim._message_add_suggested_recipient( + recipients, + partner=claim.partner_id, + reason=_('Customer') + ) elif claim.email_from: - self._message_add_suggested_recipient( - recipients, claim, - email=claim.email_from, reason=_('Customer Email')) + claim._message_add_suggested_recipient( + recipients, + email=claim.email_from, + reason=_('Customer Email') + ) except exceptions.AccessError: # no read access rights -> just ignore suggested recipients # because this imply modifying followers @@ -190,14 +183,21 @@ class CrmClaim(models.Model): browse(code_id).ir_sequence_id.code sequence = self.env['ir.sequence'] - return claim_type_code and sequence.get(claim_type_code) or '/' + return claim_type_code and sequence.next_by_code( + claim_type_code + ) or '/' @api.model def create(self, values): values = values or {} if 'code' not in values or not values.get('code') \ or values.get('code') == '/': - values['code'] = self._get_sequence_number(values['claim_type']) + + claim_type = values.get('claim_type') + if not claim_type: + claim_type = self._get_claim_type_default().id + + values['code'] = self._get_sequence_number(claim_type) return super(CrmClaim, self).create(values) diff --git a/crm_claim_rma/models/invoice_no_date.py b/crm_claim_rma/models/invoice_no_date.py index 981c38d4..d433f430 100644 --- a/crm_claim_rma/models/invoice_no_date.py +++ b/crm_claim_rma/models/invoice_no_date.py @@ -1,31 +1,11 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright 2015 Eezee-It, MONK Software, Vauxoo -# Copyright 2013 Camptocamp -# Copyright 2009-2013 Akretion, -# Author: Emmanuel Samyn, Raphaël Valyi, Sébastien Beau, -# Benoît Guillot, Joel Grand-Guillaume, Leonardo Donelli, -# Osval Reyes -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2015 Eezee-It, MONK Software, Vauxoo +# © 2013 Camptocamp +# © 2009-2013 Akretion, +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). class InvoiceNoDate(Exception): - """ - Raised when a warranty cannot be computed for a claim line + """ Raised when a warranty cannot be computed for a claim line because the invoice has no date. """ diff --git a/crm_claim_rma/models/product_no_supplier.py b/crm_claim_rma/models/product_no_supplier.py index 7b637406..847dbb56 100644 --- a/crm_claim_rma/models/product_no_supplier.py +++ b/crm_claim_rma/models/product_no_supplier.py @@ -1,32 +1,12 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright 2015 Vauxoo -# Copyright 2015 Eezee-It, MONK Software -# Copyright 2013 Camptocamp -# Copyright 2009-2013 Akretion, -# Author: Emmanuel Samyn, Raphaël Valyi, Sébastien Beau, -# Benoît Guillot, Joel Grand-Guillaume, Leonardo Donelli -# Osval Reyes -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2015 Vauxoo +# © 2015 Eezee-It, MONK Software +# © 2013 Camptocamp +# © 2009-2013 Akretion, +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). class ProductNoSupplier(Exception): - """ - Raised when a warranty cannot be computed for a claim line + """ Raised when a warranty cannot be computed for a claim line because the product has no supplier. """ diff --git a/crm_claim_rma/models/stock_move.py b/crm_claim_rma/models/stock_move.py index 2cb02204..b1e826a3 100644 --- a/crm_claim_rma/models/stock_move.py +++ b/crm_claim_rma/models/stock_move.py @@ -1,27 +1,9 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright 2015 Eezee-It, MONK Software, Vauxoo -# Copyright 2013 Camptocamp -# Copyright 2009-2013 Akretion, -# Author: Emmanuel Samyn, Raphaël Valyi, Sébastien Beau, -# Benoît Guillot, Joel Grand-Guillaume, Leonardo Donelli, -# Osval Reyes -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2015 Eezee-It, MONK Software, Vauxoo +# © 2013 Camptocamp +# © 2009-2013 Akretion, +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + from openerp import api, models @@ -32,9 +14,8 @@ class StockMove(models.Model): @api.model def create(self, vals): - """ - In case of a wrong picking out, We need to create a new stock_move in a - picking already open. + """ In case of a wrong picking out, + We need to create a new stock_move in a picking already open. To avoid having to confirm the stock_move, we override the create and confirm it at the creation only for this case. """ diff --git a/crm_claim_rma/models/stock_picking.py b/crm_claim_rma/models/stock_picking.py index ed5c330f..07f25de2 100644 --- a/crm_claim_rma/models/stock_picking.py +++ b/crm_claim_rma/models/stock_picking.py @@ -1,27 +1,9 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright 2015 Eezee-It, MONK Software, Vauxoo -# Copyright 2013 Camptocamp -# Copyright 2009-2013 Akretion, -# Author: Emmanuel Samyn, Raphaël Valyi, Sébastien Beau, -# Benoît Guillot, Joel Grand-Guillaume, Leonardo Donelli, -# Osval Reyes -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2015 Eezee-It, MONK Software, Vauxoo +# © 2013 Camptocamp +# © 2009-2013 Akretion, +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + from openerp import fields, models diff --git a/crm_claim_rma/models/substate_substate.py b/crm_claim_rma/models/substate_substate.py index 235a824e..ce97cfbf 100644 --- a/crm_claim_rma/models/substate_substate.py +++ b/crm_claim_rma/models/substate_substate.py @@ -1,34 +1,14 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright 2015 Eezee-It, MONK Software, Vauxoo -# Copyright 2013 Camptocamp -# Copyright 2009-2013 Akretion, -# Author: Emmanuel Samyn, Raphaël Valyi, Sébastien Beau, -# Benoît Guillot, Joel Grand-Guillaume, Leonardo Donelli, -# Osval Reyes -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2015 Eezee-It, MONK Software, Vauxoo +# © 2013 Camptocamp +# © 2009-2013 Akretion, +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + from openerp import fields, models class SubstateSubstate(models.Model): - - """ - To precise a state (state=refused; substates= reason 1, 2,...) + """ To precise a state (state=refused; substates= reason 1, 2,...) """ _name = "substate.substate" diff --git a/crm_claim_rma/security/ir.model.access.csv b/crm_claim_rma/security/ir.model.access.csv index 08cd096b..a7245270 100644 --- a/crm_claim_rma/security/ir.model.access.csv +++ b/crm_claim_rma/security/ir.model.access.csv @@ -1,6 +1,6 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_substate_user,substate.substate.user,model_substate_substate,base.group_sale_salesman_all_leads,1,1,1,0 -access_claim_line_user,claim.line.user,model_claim_line,base.group_sale_salesman_all_leads,1,1,1,0 +access_substate_user_all_leads,substate.substate.user,model_substate_substate,base.group_sale_salesman_all_leads,1,1,1,0 +access_claim_line_user_all_leads,claim.line.user,model_claim_line,base.group_sale_salesman_all_leads,1,1,1,0 access_substate_manager,substate.substate.manager,model_substate_substate,base.group_sale_manager,1,1,1,1 access_claim_line_manager,claim.line.manager,model_claim_line,base.group_sale_manager,1,1,1,1 access_substate_user,substate.substate.user,model_substate_substate,base.group_sale_salesman,1,1,1,0 diff --git a/crm_claim_rma/test/test_invoice_refund.yml b/crm_claim_rma/test/test_invoice_refund.yml index cbe6bc4c..671c0e64 100644 --- a/crm_claim_rma/test/test_invoice_refund.yml +++ b/crm_claim_rma/test/test_invoice_refund.yml @@ -3,12 +3,11 @@ - I create a customer invoice - - !record {model: account.invoice, id: account_invoice_claim_refund, view: account.invoice_form}: - payment_term: account.account_payment_term_advance - journal_id: account.sales_journal + !record {model: account.invoice, id: account_invoice_claim_refund}: + payment_term_id: account.account_payment_term_advance partner_id: base.res_partner_3 name: 'Test Customer Invoice' - invoice_line: + invoice_line_ids: - product_id: product.product_product_5 quantity: 10.0 - product_id: product.product_product_4 @@ -54,4 +53,3 @@ refund_lines = self.pool.get('account.invoice.line').browse(cr, uid, refund_line_ids) assert ref('product.product_product_4') in [refund_lines[0].product_id.id, refund_lines[1].product_id.id], "First line is checked" assert ref('product.product_product_5') in [refund_lines[0].product_id.id, refund_lines[1].product_id.id], "Second line is checked" - diff --git a/crm_claim_rma/tests/__init__.py b/crm_claim_rma/tests/__init__.py index 0cc244e0..a1cde8bb 100644 --- a/crm_claim_rma/tests/__init__.py +++ b/crm_claim_rma/tests/__init__.py @@ -1,21 +1,4 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Author: Yannick Vaucher -# Copyright 2014 Camptocamp SA -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## + +from . import test_claim from . import test_picking_creation diff --git a/crm_claim_rma/tests/test_claim.py b/crm_claim_rma/tests/test_claim.py new file mode 100644 index 00000000..c1456684 --- /dev/null +++ b/crm_claim_rma/tests/test_claim.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# © 2016 Cyril Gaudin (Camptocamp) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp.tests import TransactionCase + + +class TestClaim(TransactionCase): + + def test_create__no_claim_type(self): + # Just test the case when claim_type is not in values and default value + # is not yet filled by BaseModel.create as we override this method + # and our code need claim_type to generate code + claim = self.env['crm.claim'].create({'name': 'Test claim'}) + + self.assertEqual( + self.env.ref('crm_claim_type.crm_claim_type_customer'), + claim.claim_type, + ) + self.assertIsNotNone(claim.code) + self.assertTrue(claim.code.startswith('RMA-C/')) + + def test_create__with_claim_type(self): + supplier_type = self.env.ref('crm_claim_type.crm_claim_type_supplier') + claim = self.env['crm.claim'].create({ + 'name': 'Test claim', + 'claim_type': supplier_type.id, + }) + + self.assertEqual(supplier_type, claim.claim_type) + self.assertIsNotNone(claim.code) + self.assertTrue(claim.code.startswith('RMA-V/')) diff --git a/crm_claim_rma/tests/test_picking_creation.py b/crm_claim_rma/tests/test_picking_creation.py index c884da8c..315ec3dc 100644 --- a/crm_claim_rma/tests/test_picking_creation.py +++ b/crm_claim_rma/tests/test_picking_creation.py @@ -1,27 +1,9 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Author: Yannick Vaucher -# Yanina Aular -# Copyright 2015 Vauxoo -# Copyright 2014 Camptocamp SA -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2015 Vauxoo +# © 2014 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + from openerp.tests import common -from openerp.tools.safe_eval import safe_eval class TestPickingCreation(common.TransactionCase): @@ -36,18 +18,37 @@ class TestPickingCreation(common.TransactionCase): claim = self.env['crm.claim'] self.product_id = self.env.ref('product.product_product_4') - self.partner_id = self.env.ref('base.res_partner_12') self.customer_location_id = self.env.ref( - 'stock.stock_location_customers') + 'stock.stock_location_customers' + ) - sale_order_agrolait_demo = self.env.ref('sale.sale_order_1') - self.assertTrue(sale_order_agrolait_demo.invoice_ids, - "The Order Sale of Agrolait not have Invoice") - invoice_agrolait = sale_order_agrolait_demo.invoice_ids[0] - invoice_agrolait.\ - signal_workflow('invoice_open') + uom_unit = self.env.ref('product.product_uom_unit') + self.sale_order = self.env['sale.order'].create({ + 'state': 'done', + 'partner_id': self.env.ref('base.res_partner_2').id, + 'partner_invoice_id': self.env.ref('base.res_partner_2').id, + 'partner_shipping_id': self.env.ref('base.res_partner_2').id, + 'pricelist_id': self.env.ref('product.list0').id, + 'order_line': [ + (0, False, { + 'name': product.name, + 'product_id': product.id, + 'product_uom_qty': qty, + 'qty_delivered': qty, + 'product_uom': uom_unit.id, + 'price_unit': product.list_price + + }) for product, qty in [ + (self.env.ref('product.product_product_25'), 3), + (self.env.ref('product.product_product_30'), 5), + (self.env.ref('product.product_product_33'), 2), + ] + ] + }) + invoice_id = self.sale_order.action_invoice_create()[0] + self.invoice = self.env['account.invoice'].browse(invoice_id) # Create the claim with a claim line self.claim_id = claim.create( @@ -58,7 +59,7 @@ class TestPickingCreation(common.TransactionCase): 'crm_claim_type_customer').id, 'delivery_address_id': self.partner_id.id, 'partner_id': self.env.ref('base.res_partner_2').id, - 'invoice_id': invoice_agrolait.id, + 'invoice_id': invoice_id, }) self.claim_id.with_context({'create_lines': True}).\ _onchange_invoice_warehouse_type_date() @@ -137,7 +138,6 @@ class TestPickingCreation(common.TransactionCase): def test_02_new_product_return(self): """Test wizard creates a correct picking for product return - """ wizard = self.wizard_make_picking.with_context({ 'active_id': self.claim_id.id, @@ -159,36 +159,51 @@ class TestPickingCreation(common.TransactionCase): def test_03_invoice_refund(self): claim_id = self.env['crm.claim'].browse( - self.ref('crm_claim.crm_claim_6')) - invoice_id = self.env['account.invoice'].browse( - self.ref('account.invoice_5')) + self.ref('crm_claim.crm_claim_6') + ) + self.invoice.confirm_paid() claim_id.write({ - 'invoice_id': invoice_id.id + 'invoice_id': self.invoice.id }) claim_id.with_context({'create_lines': True}).\ _onchange_invoice_warehouse_type_date() invoice_refund_wizard_id = self.env['account.invoice.refund'].\ with_context({ - 'active_ids': [claim_id.invoice_id.id], + # Test that invoice_ids is correctly passed as active_ids + 'invoice_ids': [claim_id.invoice_id.id], 'claim_line_ids': [[4, cl.id, False] for cl in claim_id.claim_line_ids], - }).create({ - 'description': "Testing Invoice Refund for Claim" - }) + 'description': "Testing Invoice Refund for Claim", + }).create({}) + + self.assertEqual( + "Testing Invoice Refund for Claim", + invoice_refund_wizard_id.description + ) res = invoice_refund_wizard_id.invoice_refund() self.assertTrue(res) self.assertEquals(res['res_model'], 'account.invoice') - self.assertEquals(safe_eval(res['context'])['type'], 'out_refund') + self.assertEqual(2, len(res['domain'])) + + # Second leaf is ('id', 'in', [created_invoice_id]) + self.assertEqual(('id', 'in'), res['domain'][1][:2]) + self.assertEqual(1, len(res['domain'][1][2])) + + refund_invoice = self.env['account.invoice'].browse( + res['domain'][1][2] + ) + self.assertEqual('out_refund', refund_invoice.type) def test_04_display_name(self): """ It tests that display_name for each line has a message for it """ claim_line_ids = self.env['crm.claim'].browse( - self.ref('crm_claim.crm_claim_6'))[0].claim_line_ids + self.ref('crm_claim.crm_claim_6') + )[0].claim_line_ids all_values = sum([bool(line_id.display_name) for line_id in claim_line_ids]) diff --git a/crm_claim_rma/views/account_invoice.xml b/crm_claim_rma/views/account_invoice.xml index 5609e25b..3568fb19 100644 --- a/crm_claim_rma/views/account_invoice.xml +++ b/crm_claim_rma/views/account_invoice.xml @@ -1,20 +1,18 @@ - - - + + - - crm_claim_rma.invoice_form - account.invoice - - - - - - - - - - - - + + crm_claim_rma.invoice_form + account.invoice + + + + + + + + + + + diff --git a/crm_claim_rma/views/claim_line.xml b/crm_claim_rma/views/claim_line.xml index 235ad0cb..140c5e4a 100644 --- a/crm_claim_rma/views/claim_line.xml +++ b/crm_claim_rma/views/claim_line.xml @@ -1,109 +1,110 @@ - - - - CRM - Claims Search - claim.line - - - + + CRM - Claims Search + claim.line + + + - + - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + context="{'group_by':'invoice_id'}"/> - - + context="{'group_by':'product_id'}"/> + - + - + - - - - - - + + + + - - CRM - Claims Tree - claim.line - - - - - - - - - - - - -