From 4b7dc38806d1b5a0b5dc73c6e3b2a79a174b6bf6 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Wed, 23 Aug 2017 01:52:45 +0200 Subject: [PATCH 1/5] Add modules agreement_account and agreement_sale --- agreement_account/README.rst | 74 ++++++++++++++++++ agreement_account/__init__.py | 3 + agreement_account/__manifest__.py | 22 ++++++ agreement_account/demo/demo.xml | 35 +++++++++ agreement_account/models/__init__.py | 4 + agreement_account/models/account_invoice.py | 15 ++++ agreement_account/models/sale_agreement.py | 42 ++++++++++ .../security/ir.model.access.csv | 3 + .../security/sale_agreement_security.xml | 17 ++++ agreement_account/views/account_invoice.xml | 37 +++++++++ agreement_account/views/sale_agreement.xml | 77 +++++++++++++++++++ agreement_sale/README.rst | 49 ++++++++++++ agreement_sale/__init__.py | 4 + agreement_sale/__manifest__.py | 23 ++++++ agreement_sale/models/__init__.py | 4 + agreement_sale/models/sale_agreement.py | 14 ++++ agreement_sale/models/sale_order.py | 20 +++++ agreement_sale/views/sale_agreement.xml | 24 ++++++ agreement_sale/views/sale_order.xml | 35 +++++++++ agreement_sale/wizard/__init__.py | 3 + .../wizard/sale_make_invoice_advance.py | 17 ++++ oca_dependencies.txt | 3 +- 22 files changed, 524 insertions(+), 1 deletion(-) create mode 100644 agreement_account/README.rst create mode 100644 agreement_account/__init__.py create mode 100644 agreement_account/__manifest__.py create mode 100644 agreement_account/demo/demo.xml create mode 100644 agreement_account/models/__init__.py create mode 100644 agreement_account/models/account_invoice.py create mode 100644 agreement_account/models/sale_agreement.py create mode 100644 agreement_account/security/ir.model.access.csv create mode 100644 agreement_account/security/sale_agreement_security.xml create mode 100644 agreement_account/views/account_invoice.xml create mode 100644 agreement_account/views/sale_agreement.xml create mode 100644 agreement_sale/README.rst create mode 100644 agreement_sale/__init__.py create mode 100644 agreement_sale/__manifest__.py create mode 100644 agreement_sale/models/__init__.py create mode 100644 agreement_sale/models/sale_agreement.py create mode 100644 agreement_sale/models/sale_order.py create mode 100644 agreement_sale/views/sale_agreement.xml create mode 100644 agreement_sale/views/sale_order.xml create mode 100644 agreement_sale/wizard/__init__.py create mode 100644 agreement_sale/wizard/sale_make_invoice_advance.py diff --git a/agreement_account/README.rst b/agreement_account/README.rst new file mode 100644 index 00000000..f8aac0db --- /dev/null +++ b/agreement_account/README.rst @@ -0,0 +1,74 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +=================== +Agreement (Account) +=================== + +This module adds a *Sale Agreement* object with the following properties: + +* link to a customer, +* name, +* code, +* signature date. + +You can link a customer invoice to a sale agreement. + +If you also install the module *agreement_sale*, you will be able to link a quotation/sale order to an agreement, and this information will be copied to the invoice. + +A *Sale Agreement* can be used for: + +* Private business contracts +* Public markets + +It will allow you to group all the orders and invoices related to the same agreement and display the references of this agreement on the documents where you have to display it. For example, the *code* property of the sale agreement is used in the module *account_invoice_factur-x* (from the `edi `_ project) in the XML tag */CrossIndustryInvoice/SupplyChainTradeTransaction/ApplicableHeaderTradeAgreement/ContractReferencedDocument/IssuerAssignedID*. + +The main differences with the *Contract* object of Odoo: + +* a contract is an analytic account; a sale agreement is not related to analytic accounting. +* on the invoice, the contract/analytic account is per-line; a sale agreement is attached to the invoice (not to the lines). +* a sale agreement is a very simple object with just a few basic fields; a contract has a lot of properties and a lot of related features. + +Configuration +============= + +Go to the menu *Accounting > Configuration > Management > Sale Agreements* to create new agreements. + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/110/10.0 + +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. + +Credits +======= + +Contributors +------------ + +* Alexis de Lattre + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/agreement_account/__init__.py b/agreement_account/__init__.py new file mode 100644 index 00000000..cde864ba --- /dev/null +++ b/agreement_account/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import models diff --git a/agreement_account/__manifest__.py b/agreement_account/__manifest__.py new file mode 100644 index 00000000..21658f06 --- /dev/null +++ b/agreement_account/__manifest__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# © 2017 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': u'Agreement (Account)', + 'summary': "Adds a sale agreement object linked to a customer invoice", + 'version': '10.0.1.0.0', + 'category': 'Contract', + 'author': "Akretion,Odoo Community Association (OCA)", + 'website': 'http://www.akretion.com', + 'license': 'AGPL-3', + 'depends': ['account'], + 'data': [ + 'security/ir.model.access.csv', + 'security/sale_agreement_security.xml', + 'views/sale_agreement.xml', + 'views/account_invoice.xml', + ], + 'demo': ['demo/demo.xml'], + 'installable': True, +} diff --git a/agreement_account/demo/demo.xml b/agreement_account/demo/demo.xml new file mode 100644 index 00000000..d45cd2d8 --- /dev/null +++ b/agreement_account/demo/demo.xml @@ -0,0 +1,35 @@ + + + + + + + + C2C-IT0042 + Hardware IT + + + + + C2C-IT0043 + Fiber access office Lausanne + + + + + AGR-VETO001 + Vétérinaire + + + + + AGR-TEL001 + Wazo IPBX deployment and maintenance + + + + + diff --git a/agreement_account/models/__init__.py b/agreement_account/models/__init__.py new file mode 100644 index 00000000..16999ee3 --- /dev/null +++ b/agreement_account/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +from . import sale_agreement +from . import account_invoice diff --git a/agreement_account/models/account_invoice.py b/agreement_account/models/account_invoice.py new file mode 100644 index 00000000..c1312f2e --- /dev/null +++ b/agreement_account/models/account_invoice.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# © 2017 Akretion (http://www.akretion.com) +# @author: Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models, fields + + +class AccountInvoice(models.Model): + _inherit = 'account.invoice' + + sale_agreement_id = fields.Many2one( + 'sale.agreement', string='Sale Agreement', ondelete='restrict', + readonly=True, states={'draft': [('readonly', False)]}, + track_visibility='onchange') diff --git a/agreement_account/models/sale_agreement.py b/agreement_account/models/sale_agreement.py new file mode 100644 index 00000000..1749bf6c --- /dev/null +++ b/agreement_account/models/sale_agreement.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# © 2017 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo import models, fields + + +class SaleAgreement(models.Model): + _name = 'sale.agreement' + _description = 'Sale Agreement' + + code = fields.Char( + string='Code', required=True, copy=False) + name = fields.Char(string='Name', required=True) + partner_id = fields.Many2one( + 'res.partner', string='Customer', ondelete='restrict', required=True, + domain=[('customer', '=', True), ('parent_id', '=', False)]) + company_id = fields.Many2one( + 'res.company', string='Company', + default=lambda self: self.env['res.company']._company_default_get( + 'sale.agreement')) + active = fields.Boolean(string='Active', default=True) + signature_date = fields.Date(string='Signature Date') + invoice_ids = fields.One2many( + 'account.invoice', 'sale_agreement_id', string='Invoices', + readonly=True) + + def name_get(self): + res = [] + for agr in self: + name = agr.name + if agr.code: + name = u'[%s] %s' % (agr.code, agr.name) + res.append((agr.id, name)) + return res + + _sql_constraints = [( + 'code_partner_company_unique', + 'unique(code, partner_id, company_id)', + 'This sale agreement code already exists for this customer!' + )] diff --git a/agreement_account/security/ir.model.access.csv b/agreement_account/security/ir.model.access.csv new file mode 100644 index 00000000..b5940477 --- /dev/null +++ b/agreement_account/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_sale_agreement_read,Read access on sale.agreement to Employees,model_sale_agreement,base.group_user,1,0,0,0 +access_sale_agreement_full,Full access on sale.agreement to Invoicing and Payment grp,model_sale_agreement,account.group_account_invoice,1,1,1,1 diff --git a/agreement_account/security/sale_agreement_security.xml b/agreement_account/security/sale_agreement_security.xml new file mode 100644 index 00000000..48960ca6 --- /dev/null +++ b/agreement_account/security/sale_agreement_security.xml @@ -0,0 +1,17 @@ + + + + + + + + Sale Agreement multi-company + + ['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])] + + + + diff --git a/agreement_account/views/account_invoice.xml b/agreement_account/views/account_invoice.xml new file mode 100644 index 00000000..6e9100b5 --- /dev/null +++ b/agreement_account/views/account_invoice.xml @@ -0,0 +1,37 @@ + + + + + + + + sale.agreement.account.invoice.form + account.invoice + + + + + + + + + + + sale.agreement.account.invoice.search + account.invoice + + + + + + + + + + diff --git a/agreement_account/views/sale_agreement.xml b/agreement_account/views/sale_agreement.xml new file mode 100644 index 00000000..b002047e --- /dev/null +++ b/agreement_account/views/sale_agreement.xml @@ -0,0 +1,77 @@ + + + + + + + + sale.agreement.form + sale.agreement + +
+
+ +
+ + + + + + + + + + +
+
+
+ + + sale.agreement.tree + sale.agreement + + + + + + + + + + + + + sale.agreement.search + sale.agreement + + + + + + + + + + + + + + + Sale Agreements + sale.agreement + tree,form + + + + +
diff --git a/agreement_sale/README.rst b/agreement_sale/README.rst new file mode 100644 index 00000000..4726a7c8 --- /dev/null +++ b/agreement_sale/README.rst @@ -0,0 +1,49 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +================ +Agreement (Sale) +================ + +This module is an extension of the module *agreement_account* for sale orders. + +With this module, you will be able to link a quotation/sale order to a sale agreement. Upon invoice creation, this information will be copied to the customer invoice. + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/110/10.0 + +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. + +Credits +======= + +Contributors +------------ + +* Alexis de Lattre + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/agreement_sale/__init__.py b/agreement_sale/__init__.py new file mode 100644 index 00000000..35e7c960 --- /dev/null +++ b/agreement_sale/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +from . import models +from . import wizard diff --git a/agreement_sale/__manifest__.py b/agreement_sale/__manifest__.py new file mode 100644 index 00000000..78efe7c4 --- /dev/null +++ b/agreement_sale/__manifest__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# © 2017 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': u'Agreement (Sale)', + 'summary': "Link a sale agreement to a sale order and copy to invoice", + 'version': '10.0.1.0.0', + 'category': 'Contract', + 'author': "Akretion,Odoo Community Association (OCA)", + 'website': 'http://www.akretion.com', + 'license': 'AGPL-3', + 'depends': [ + 'agreement_account', + 'sale_commercial_partner', + ], + 'data': [ + 'views/sale_order.xml', + 'views/sale_agreement.xml', + ], + 'installable': True, + 'auto_install': True, +} diff --git a/agreement_sale/models/__init__.py b/agreement_sale/models/__init__.py new file mode 100644 index 00000000..5296cfb7 --- /dev/null +++ b/agreement_sale/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +from . import sale_order +from . import sale_agreement diff --git a/agreement_sale/models/sale_agreement.py b/agreement_sale/models/sale_agreement.py new file mode 100644 index 00000000..c8ca1925 --- /dev/null +++ b/agreement_sale/models/sale_agreement.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# © 2017 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo import models, fields + + +class SaleAgreement(models.Model): + _inherit = 'sale.agreement' + + sale_ids = fields.One2many( + 'sale.order', 'sale_agreement_id', string='Sale Orders', readonly=True, + domain=[('state', 'not in', ('draft', 'sent', 'cancel'))]) diff --git a/agreement_sale/models/sale_order.py b/agreement_sale/models/sale_order.py new file mode 100644 index 00000000..888291a5 --- /dev/null +++ b/agreement_sale/models/sale_order.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# © 2017 Akretion (http://www.akretion.com) +# @author: Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models, fields + + +class SaleOrder(models.Model): + _inherit = 'sale.order' + + sale_agreement_id = fields.Many2one( + 'sale.agreement', string='Sale Agreement', ondelete='restrict', + track_visibility='onchange', readonly=True, + states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}) + + def _prepare_invoice(self): + vals = super(SaleOrder, self)._prepare_invoice() + vals['sale_agreement_id'] = self.sale_agreement_id.id or False + return vals diff --git a/agreement_sale/views/sale_agreement.xml b/agreement_sale/views/sale_agreement.xml new file mode 100644 index 00000000..fd68f6dc --- /dev/null +++ b/agreement_sale/views/sale_agreement.xml @@ -0,0 +1,24 @@ + + + + + + + + sale.agreement.form + sale.agreement + + + + + + + + + + + + diff --git a/agreement_sale/views/sale_order.xml b/agreement_sale/views/sale_order.xml new file mode 100644 index 00000000..ae6fd3bd --- /dev/null +++ b/agreement_sale/views/sale_order.xml @@ -0,0 +1,35 @@ + + + + + + + + sale.agreement.sale.order.form + sale.order + + + + + + + + + + sale.agreement.sale.order.search + sale.order + + + + + + + + + + diff --git a/agreement_sale/wizard/__init__.py b/agreement_sale/wizard/__init__.py new file mode 100644 index 00000000..1eb17ffa --- /dev/null +++ b/agreement_sale/wizard/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import sale_make_invoice_advance diff --git a/agreement_sale/wizard/sale_make_invoice_advance.py b/agreement_sale/wizard/sale_make_invoice_advance.py new file mode 100644 index 00000000..fa8080f4 --- /dev/null +++ b/agreement_sale/wizard/sale_make_invoice_advance.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# © 2017 Akretion (http://www.akretion.com) +# @author: Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class SaleAdvancePaymentInv(models.TransientModel): + _inherit = 'sale.advance.payment.inv' + + def _create_invoice(self, order, so_line, amount): + inv = super(SaleAdvancePaymentInv, self)._create_invoice( + order, so_line, amount) + if order.sale_agreement_id: + inv.sale_agreement_id = order.sale_agreement_id.id + return inv diff --git a/oca_dependencies.txt b/oca_dependencies.txt index 98a804d4..4ac83d71 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -1 +1,2 @@ -bank-payment \ No newline at end of file +bank-payment +sale-workflow From b795f33d1730d19074e2edb5bca798cda0ff87fb Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Wed, 23 Aug 2017 16:18:45 +0200 Subject: [PATCH 2/5] Copy sale_agreement_id from invoice to refund --- agreement_account/models/account_invoice.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/agreement_account/models/account_invoice.py b/agreement_account/models/account_invoice.py index c1312f2e..33db902e 100644 --- a/agreement_account/models/account_invoice.py +++ b/agreement_account/models/account_invoice.py @@ -3,7 +3,7 @@ # @author: Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import models, fields +from odoo import models, fields, api class AccountInvoice(models.Model): @@ -13,3 +13,14 @@ class AccountInvoice(models.Model): 'sale.agreement', string='Sale Agreement', ondelete='restrict', readonly=True, states={'draft': [('readonly', False)]}, track_visibility='onchange') + + @api.model + def _prepare_refund( + self, invoice, date_invoice=None, date=None, description=None, + journal_id=None): + values = super(AccountInvoice, self)._prepare_refund( + invoice, date_invoice=date_invoice, date=date, + description=description, journal_id=journal_id) + if invoice.sale_agreement_id: + values['sale_agreement_id'] = invoice.sale_agreement_id.id + return values From 90fda6ba7345c816b5ee6ad5acf1c98e5e237a12 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Sun, 10 Sep 2017 22:56:58 +0200 Subject: [PATCH 3/5] Rename 'sale.agreement' model to 'agreement' Add type field on 'agreement': 'sale' or 'purchase' Add agreement_id field on supplier invoices --- agreement_account/README.rst | 21 +++++---- agreement_account/__manifest__.py | 6 +-- agreement_account/demo/demo.xml | 32 +++++++++++-- agreement_account/models/__init__.py | 2 +- agreement_account/models/account_invoice.py | 8 ++-- .../{sale_agreement.py => agreement.py} | 27 +++++++---- ...nt_security.xml => agreement_security.xml} | 6 +-- .../security/ir.model.access.csv | 4 +- agreement_account/views/account_invoice.xml | 28 ++++++++--- .../{sale_agreement.xml => agreement.xml} | 46 +++++++++++-------- agreement_sale/__manifest__.py | 4 +- agreement_sale/models/__init__.py | 2 +- .../{sale_agreement.py => agreement.py} | 6 +-- agreement_sale/models/sale_order.py | 6 +-- .../{sale_agreement.xml => agreement.xml} | 10 ++-- agreement_sale/views/sale_order.xml | 12 ++--- .../wizard/sale_make_invoice_advance.py | 4 +- 17 files changed, 140 insertions(+), 84 deletions(-) rename agreement_account/models/{sale_agreement.py => agreement.py} (55%) rename agreement_account/security/{sale_agreement_security.xml => agreement_security.xml} (67%) rename agreement_account/views/{sale_agreement.xml => agreement.xml} (57%) rename agreement_sale/models/{sale_agreement.py => agreement.py} (66%) rename agreement_sale/views/{sale_agreement.xml => agreement.xml} (58%) diff --git a/agreement_account/README.rst b/agreement_account/README.rst index f8aac0db..2137e98c 100644 --- a/agreement_account/README.rst +++ b/agreement_account/README.rst @@ -6,34 +6,35 @@ Agreement (Account) =================== -This module adds a *Sale Agreement* object with the following properties: +This module adds an *Agreement* object with the following properties: -* link to a customer, +* type (*Sale* or *Purchase*), +* link to a partner, * name, * code, * signature date. -You can link a customer invoice to a sale agreement. +You can link an invoice to an agreement. -If you also install the module *agreement_sale*, you will be able to link a quotation/sale order to an agreement, and this information will be copied to the invoice. +If you also install the module *agreement_sale*, you will be able to link a quotation/sale order to an agreement, and this information will be copied to the customer invoice. -A *Sale Agreement* can be used for: +An *Agreement* can be used for: * Private business contracts * Public markets -It will allow you to group all the orders and invoices related to the same agreement and display the references of this agreement on the documents where you have to display it. For example, the *code* property of the sale agreement is used in the module *account_invoice_factur-x* (from the `edi `_ project) in the XML tag */CrossIndustryInvoice/SupplyChainTradeTransaction/ApplicableHeaderTradeAgreement/ContractReferencedDocument/IssuerAssignedID*. +It will allow you to group all the orders and invoices related to the same agreement and display the references of this agreement on the documents where you have to display it. For example, the *code* property of the agreement is used in the module *account_invoice_factur-x* (from the `edi `_ project) in the XML tag */CrossIndustryInvoice/SupplyChainTradeTransaction/ApplicableHeaderTradeAgreement/ContractReferencedDocument/IssuerAssignedID*. The main differences with the *Contract* object of Odoo: -* a contract is an analytic account; a sale agreement is not related to analytic accounting. -* on the invoice, the contract/analytic account is per-line; a sale agreement is attached to the invoice (not to the lines). -* a sale agreement is a very simple object with just a few basic fields; a contract has a lot of properties and a lot of related features. +* a contract is an analytic account; an agreement is not related to analytic accounting. +* on the invoice, the contract/analytic account is per-line; an agreement is attached to the invoice (not to the lines). +* an agreement is a very simple object with just a few basic fields; a contract has a lot of properties and a lot of related features. Configuration ============= -Go to the menu *Accounting > Configuration > Management > Sale Agreements* to create new agreements. +Go to the menu *Accounting > Configuration > Management > Agreements* to create new agreements. Usage ===== diff --git a/agreement_account/__manifest__.py b/agreement_account/__manifest__.py index 21658f06..d1b7a17b 100644 --- a/agreement_account/__manifest__.py +++ b/agreement_account/__manifest__.py @@ -4,7 +4,7 @@ { 'name': u'Agreement (Account)', - 'summary': "Adds a sale agreement object linked to a customer invoice", + 'summary': "Adds an agreement object linked to an invoice", 'version': '10.0.1.0.0', 'category': 'Contract', 'author': "Akretion,Odoo Community Association (OCA)", @@ -13,8 +13,8 @@ 'depends': ['account'], 'data': [ 'security/ir.model.access.csv', - 'security/sale_agreement_security.xml', - 'views/sale_agreement.xml', + 'security/agreement_security.xml', + 'views/agreement.xml', 'views/account_invoice.xml', ], 'demo': ['demo/demo.xml'], diff --git a/agreement_account/demo/demo.xml b/agreement_account/demo/demo.xml index d45cd2d8..2d08d890 100644 --- a/agreement_account/demo/demo.xml +++ b/agreement_account/demo/demo.xml @@ -7,28 +7,52 @@ - + C2C-IT0042 Hardware IT + sale + 2017-09-10 - + C2C-IT0043 Fiber access office Lausanne + sale + - + AGR-VETO001 Vétérinaire + sale + 2017-08-01 - + AGR-TEL001 Wazo IPBX deployment and maintenance + sale + 2017-05-05 + + + + BUY-VOIP012 + SIP Phones supply + + purchase + + + + + BUY-VOIP013 + SIP-ISDN gateways + + purchase + 2017-09-02 diff --git a/agreement_account/models/__init__.py b/agreement_account/models/__init__.py index 16999ee3..55d56700 100644 --- a/agreement_account/models/__init__.py +++ b/agreement_account/models/__init__.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- -from . import sale_agreement +from . import agreement from . import account_invoice diff --git a/agreement_account/models/account_invoice.py b/agreement_account/models/account_invoice.py index 33db902e..5b9d4d79 100644 --- a/agreement_account/models/account_invoice.py +++ b/agreement_account/models/account_invoice.py @@ -9,8 +9,8 @@ from odoo import models, fields, api class AccountInvoice(models.Model): _inherit = 'account.invoice' - sale_agreement_id = fields.Many2one( - 'sale.agreement', string='Sale Agreement', ondelete='restrict', + agreement_id = fields.Many2one( + 'agreement', string='Agreement', ondelete='restrict', readonly=True, states={'draft': [('readonly', False)]}, track_visibility='onchange') @@ -21,6 +21,6 @@ class AccountInvoice(models.Model): values = super(AccountInvoice, self)._prepare_refund( invoice, date_invoice=date_invoice, date=date, description=description, journal_id=journal_id) - if invoice.sale_agreement_id: - values['sale_agreement_id'] = invoice.sale_agreement_id.id + if invoice.agreement_id: + values['agreement_id'] = invoice.agreement_id.id return values diff --git a/agreement_account/models/sale_agreement.py b/agreement_account/models/agreement.py similarity index 55% rename from agreement_account/models/sale_agreement.py rename to agreement_account/models/agreement.py index 1749bf6c..5e8d8900 100644 --- a/agreement_account/models/sale_agreement.py +++ b/agreement_account/models/agreement.py @@ -6,25 +6,32 @@ from odoo import models, fields -class SaleAgreement(models.Model): - _name = 'sale.agreement' - _description = 'Sale Agreement' +class Agreement(models.Model): + _name = 'agreement' + _description = 'Agreement' code = fields.Char( string='Code', required=True, copy=False) name = fields.Char(string='Name', required=True) + type = fields.Selection([ + ('sale', 'Sale'), + ('purchase', 'Purchase'), + ], string='Type', required=True) partner_id = fields.Many2one( - 'res.partner', string='Customer', ondelete='restrict', required=True, - domain=[('customer', '=', True), ('parent_id', '=', False)]) + 'res.partner', string='Partner', ondelete='restrict', required=True, + domain=[('parent_id', '=', False)]) company_id = fields.Many2one( 'res.company', string='Company', default=lambda self: self.env['res.company']._company_default_get( - 'sale.agreement')) + 'agreement')) active = fields.Boolean(string='Active', default=True) signature_date = fields.Date(string='Signature Date') - invoice_ids = fields.One2many( - 'account.invoice', 'sale_agreement_id', string='Invoices', - readonly=True) + out_invoice_ids = fields.One2many( + 'account.invoice', 'agreement_id', string='Customer Invoices', + readonly=True, domain=[('type', 'in', ('out_invoice', 'out_refund'))]) + in_invoice_ids = fields.One2many( + 'account.invoice', 'agreement_id', string='Supplier Invoices', + readonly=True, domain=[('type', 'in', ('in_invoice', 'in_refund'))]) def name_get(self): res = [] @@ -38,5 +45,5 @@ class SaleAgreement(models.Model): _sql_constraints = [( 'code_partner_company_unique', 'unique(code, partner_id, company_id)', - 'This sale agreement code already exists for this customer!' + 'This agreement code already exists for this partner!' )] diff --git a/agreement_account/security/sale_agreement_security.xml b/agreement_account/security/agreement_security.xml similarity index 67% rename from agreement_account/security/sale_agreement_security.xml rename to agreement_account/security/agreement_security.xml index 48960ca6..d645ef6d 100644 --- a/agreement_account/security/sale_agreement_security.xml +++ b/agreement_account/security/agreement_security.xml @@ -7,9 +7,9 @@ - - Sale Agreement multi-company - + + Agreement multi-company + ['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])] diff --git a/agreement_account/security/ir.model.access.csv b/agreement_account/security/ir.model.access.csv index b5940477..fd23275e 100644 --- a/agreement_account/security/ir.model.access.csv +++ b/agreement_account/security/ir.model.access.csv @@ -1,3 +1,3 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_sale_agreement_read,Read access on sale.agreement to Employees,model_sale_agreement,base.group_user,1,0,0,0 -access_sale_agreement_full,Full access on sale.agreement to Invoicing and Payment grp,model_sale_agreement,account.group_account_invoice,1,1,1,1 +access_agreement_read,Read access on agreement to Employees,model_agreement,base.group_user,1,0,0,0 +access_agreement_full,Full access on agreement to Invoicing and Payment grp,model_agreement,account.group_account_invoice,1,1,1,1 diff --git a/agreement_account/views/account_invoice.xml b/agreement_account/views/account_invoice.xml index 6e9100b5..ddef6e28 100644 --- a/agreement_account/views/account_invoice.xml +++ b/agreement_account/views/account_invoice.xml @@ -8,27 +8,41 @@ - sale.agreement.account.invoice.form + agreement.customer.invoice.form account.invoice - + + + + + + + + agreement.supplier.invoice.form + account.invoice + + + + - sale.agreement.account.invoice.search + agreement.account.invoice.search account.invoice - + diff --git a/agreement_account/views/sale_agreement.xml b/agreement_account/views/agreement.xml similarity index 57% rename from agreement_account/views/sale_agreement.xml rename to agreement_account/views/agreement.xml index b002047e..e6a789a8 100644 --- a/agreement_account/views/sale_agreement.xml +++ b/agreement_account/views/agreement.xml @@ -7,11 +7,11 @@ - - sale.agreement.form - sale.agreement + + agreement.form + agreement -
+