blob: 217d623a8d51bd96cc6b850b05c71581284d2804 [file] [log] [blame]
Gaurava4aa80f2019-01-06 12:40:28 +05301# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2# License: GNU General Public License v3. See license.txt
3# coding=utf-8
4
5from __future__ import unicode_literals
6
7import frappe
Gauravf1e28e02019-02-13 16:46:24 +05308from frappe import _
Gaurava4aa80f2019-01-06 12:40:28 +05309from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
marination29d7a7e2020-05-27 21:53:01 +053010from frappe.permissions import add_permission, update_permission_property
Gauravf1e28e02019-02-13 16:46:24 +053011from erpnext.regional.italy import fiscal_regimes, tax_exemption_reasons, mode_of_payment_codes, vat_collectability_options
Gaurava4aa80f2019-01-06 12:40:28 +053012
13def setup(company=None, patch=True):
Saurabh9fcfc632019-02-20 13:03:50 +053014 make_custom_fields()
15 setup_report()
marination29d7a7e2020-05-27 21:53:01 +053016 add_permissions()
Gaurava4aa80f2019-01-06 12:40:28 +053017
18def make_custom_fields(update=True):
Saurabh9fcfc632019-02-20 13:03:50 +053019 invoice_item_fields = [
20 dict(fieldname='tax_rate', label='Tax Rate',
Gauravf1e28e02019-02-13 16:46:24 +053021 fieldtype='Float', insert_after='description',
22 print_hide=1, hidden=1, read_only=1),
23 dict(fieldname='tax_amount', label='Tax Amount',
24 fieldtype='Currency', insert_after='tax_rate',
25 print_hide=1, hidden=1, read_only=1, options="currency"),
26 dict(fieldname='total_amount', label='Total Amount',
27 fieldtype='Currency', insert_after='tax_amount',
28 print_hide=1, hidden=1, read_only=1, options="currency")
Saurabh9fcfc632019-02-20 13:03:50 +053029 ]
Gauravf1e28e02019-02-13 16:46:24 +053030
Rohit Waghchaure22ebaf12019-03-07 15:18:49 +053031 customer_po_fields = [
32 dict(fieldname='customer_po_details', label='Customer PO',
33 fieldtype='Section Break', insert_after='image'),
34 dict(fieldname='customer_po_no', label='Customer PO No',
35 fieldtype='Data', insert_after='customer_po_details',
36 fetch_from = 'sales_order.po_no',
Rohit Waghchaure1b7059b2019-03-12 17:44:29 +053037 print_hide=1, allow_on_submit=1, fetch_if_empty= 1, read_only=1, no_copy=1),
Rohit Waghchaure22ebaf12019-03-07 15:18:49 +053038 dict(fieldname='customer_po_clm_brk', label='',
39 fieldtype='Column Break', insert_after='customer_po_no',
40 print_hide=1, read_only=1),
41 dict(fieldname='customer_po_date', label='Customer PO Date',
42 fieldtype='Date', insert_after='customer_po_clm_brk',
43 fetch_from = 'sales_order.po_date',
Rohit Waghchaure1b7059b2019-03-12 17:44:29 +053044 print_hide=1, allow_on_submit=1, fetch_if_empty= 1, read_only=1, no_copy=1)
Rohit Waghchaure22ebaf12019-03-07 15:18:49 +053045 ]
46
Saurabh9fcfc632019-02-20 13:03:50 +053047 custom_fields = {
48 'Company': [
49 dict(fieldname='sb_e_invoicing', label='E-Invoicing',
50 fieldtype='Section Break', insert_after='date_of_establishment', print_hide=1),
51 dict(fieldname='fiscal_regime', label='Fiscal Regime',
52 fieldtype='Select', insert_after='sb_e_invoicing', print_hide=1,
Gauravb30a9b12019-03-01 12:33:19 +053053 options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), fiscal_regimes))),
Saurabh9fcfc632019-02-20 13:03:50 +053054 dict(fieldname='fiscal_code', label='Fiscal Code', fieldtype='Data', insert_after='fiscal_regime', print_hide=1,
55 description=_("Applicable if the company is an Individual or a Proprietorship")),
56 dict(fieldname='vat_collectability', label='VAT Collectability',
57 fieldtype='Select', insert_after='fiscal_code', print_hide=1,
Gauravb30a9b12019-03-01 12:33:19 +053058 options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), vat_collectability_options))),
Saurabh9fcfc632019-02-20 13:03:50 +053059 dict(fieldname='cb_e_invoicing1', fieldtype='Column Break', insert_after='vat_collectability', print_hide=1),
60 dict(fieldname='registrar_office_province', label='Province of the Registrar Office',
61 fieldtype='Data', insert_after='cb_e_invoicing1', print_hide=1, length=2),
62 dict(fieldname='registration_number', label='Registration Number',
63 fieldtype='Data', insert_after='registrar_office_province', print_hide=1, length=20),
64 dict(fieldname='share_capital_amount', label='Share Capital',
65 fieldtype='Currency', insert_after='registration_number', print_hide=1,
66 description=_('Applicable if the company is SpA, SApA or SRL')),
67 dict(fieldname='no_of_members', label='No of Members',
68 fieldtype='Select', insert_after='share_capital_amount', print_hide=1,
69 options="\nSU-Socio Unico\nSM-Piu Soci", description=_("Applicable if the company is a limited liability company")),
70 dict(fieldname='liquidation_state', label='Liquidation State',
71 fieldtype='Select', insert_after='no_of_members', print_hide=1,
72 options="\nLS-In Liquidazione\nLN-Non in Liquidazione")
73 ],
74 'Sales Taxes and Charges': [
75 dict(fieldname='tax_exemption_reason', label='Tax Exemption Reason',
76 fieldtype='Select', insert_after='included_in_print_rate', print_hide=1,
77 depends_on='eval:doc.charge_type!="Actual" && doc.rate==0.0',
Gauravb30a9b12019-03-01 12:33:19 +053078 options="\n" + "\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), tax_exemption_reasons))),
Saurabh9fcfc632019-02-20 13:03:50 +053079 dict(fieldname='tax_exemption_law', label='Tax Exempt Under',
80 fieldtype='Text', insert_after='tax_exemption_reason', print_hide=1,
81 depends_on='eval:doc.charge_type!="Actual" && doc.rate==0.0')
82 ],
83 'Customer': [
84 dict(fieldname='fiscal_code', label='Fiscal Code', fieldtype='Data', insert_after='tax_id', print_hide=1),
85 dict(fieldname='recipient_code', label='Recipient Code',
86 fieldtype='Data', insert_after='fiscal_code', print_hide=1, default="0000000"),
87 dict(fieldname='pec', label='Recipient PEC',
88 fieldtype='Data', insert_after='fiscal_code', print_hide=1),
89 dict(fieldname='is_public_administration', label='Is Public Administration',
90 fieldtype='Check', insert_after='is_internal_customer', print_hide=1,
91 description=_("Set this if the customer is a Public Administration company."),
92 depends_on='eval:doc.customer_type=="Company"'),
93 dict(fieldname='first_name', label='First Name', fieldtype='Data',
94 insert_after='salutation', print_hide=1, depends_on='eval:doc.customer_type!="Company"'),
95 dict(fieldname='last_name', label='Last Name', fieldtype='Data',
96 insert_after='first_name', print_hide=1, depends_on='eval:doc.customer_type!="Company"')
97 ],
98 'Mode of Payment': [
99 dict(fieldname='mode_of_payment_code', label='Code',
100 fieldtype='Select', insert_after='included_in_print_rate', print_hide=1,
Gauravb30a9b12019-03-01 12:33:19 +0530101 options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), mode_of_payment_codes)))
Saurabh9fcfc632019-02-20 13:03:50 +0530102 ],
103 'Payment Schedule': [
104 dict(fieldname='mode_of_payment_code', label='Code',
105 fieldtype='Select', insert_after='mode_of_payment', print_hide=1,
Gauravb30a9b12019-03-01 12:33:19 +0530106 options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), mode_of_payment_codes)),
Saurabh9fcfc632019-02-20 13:03:50 +0530107 fetch_from="mode_of_payment.mode_of_payment_code", read_only=1),
108 dict(fieldname='bank_account', label='Bank Account',
109 fieldtype='Link', insert_after='mode_of_payment_code', print_hide=1,
110 options="Bank Account"),
Gauravb30a9b12019-03-01 12:33:19 +0530111 dict(fieldname='bank_account_name', label='Bank Name',
Saurabh9fcfc632019-02-20 13:03:50 +0530112 fieldtype='Data', insert_after='bank_account', print_hide=1,
Gauravb30a9b12019-03-01 12:33:19 +0530113 fetch_from="bank_account.bank", read_only=1),
Saurabh9fcfc632019-02-20 13:03:50 +0530114 dict(fieldname='bank_account_no', label='Bank Account No',
115 fieldtype='Data', insert_after='bank_account_name', print_hide=1,
116 fetch_from="bank_account.bank_account_no", read_only=1),
117 dict(fieldname='bank_account_iban', label='IBAN',
118 fieldtype='Data', insert_after='bank_account_name', print_hide=1,
119 fetch_from="bank_account.iban", read_only=1),
Gauravb30a9b12019-03-01 12:33:19 +0530120 dict(fieldname='bank_account_swift_number', label='Swift Code (BIC)',
121 fieldtype='Data', insert_after='bank_account_iban', print_hide=1,
122 fetch_from="bank_account.swift_number", read_only=1),
Saurabh9fcfc632019-02-20 13:03:50 +0530123 ],
124 "Sales Invoice": [
125 dict(fieldname='vat_collectability', label='VAT Collectability',
126 fieldtype='Select', insert_after='taxes_and_charges', print_hide=1,
Gauravb30a9b12019-03-01 12:33:19 +0530127 options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), vat_collectability_options)),
Saurabh9fcfc632019-02-20 13:03:50 +0530128 fetch_from="company.vat_collectability"),
129 dict(fieldname='sb_e_invoicing_reference', label='E-Invoicing',
Saqib Ansaricee36702021-02-01 15:45:26 +0530130 fieldtype='Section Break', insert_after='against_income_account', print_hide=1),
Saurabh9fcfc632019-02-20 13:03:50 +0530131 dict(fieldname='company_tax_id', label='Company Tax ID',
132 fieldtype='Data', insert_after='sb_e_invoicing_reference', print_hide=1, read_only=1,
133 fetch_from="company.tax_id"),
134 dict(fieldname='company_fiscal_code', label='Company Fiscal Code',
135 fieldtype='Data', insert_after='company_tax_id', print_hide=1, read_only=1,
136 fetch_from="company.fiscal_code"),
137 dict(fieldname='company_fiscal_regime', label='Company Fiscal Regime',
138 fieldtype='Data', insert_after='company_fiscal_code', print_hide=1, read_only=1,
139 fetch_from="company.fiscal_regime"),
140 dict(fieldname='cb_e_invoicing_reference', fieldtype='Column Break',
141 insert_after='company_fiscal_regime', print_hide=1),
142 dict(fieldname='customer_fiscal_code', label='Customer Fiscal Code',
143 fieldtype='Data', insert_after='cb_e_invoicing_reference', read_only=1,
144 fetch_from="customer.fiscal_code"),
145 ],
146 'Purchase Invoice Item': invoice_item_fields,
Gauravf1e28e02019-02-13 16:46:24 +0530147 'Sales Order Item': invoice_item_fields,
148 'Delivery Note Item': invoice_item_fields,
Rohit Waghchaure22ebaf12019-03-07 15:18:49 +0530149 'Sales Invoice Item': invoice_item_fields + customer_po_fields,
Gauravf1e28e02019-02-13 16:46:24 +0530150 'Quotation Item': invoice_item_fields,
151 'Purchase Order Item': invoice_item_fields,
152 'Purchase Receipt Item': invoice_item_fields,
153 'Supplier Quotation Item': invoice_item_fields,
Saurabh9fcfc632019-02-20 13:03:50 +0530154 'Address': [
155 dict(fieldname='country_code', label='Country Code',
Rohit Waghchaure74cfe572019-02-26 20:08:26 +0530156 fieldtype='Data', insert_after='country', print_hide=1, read_only=0,
Saurabh9fcfc632019-02-20 13:03:50 +0530157 fetch_from="country.code"),
158 dict(fieldname='state_code', label='State Code',
159 fieldtype='Data', insert_after='state', print_hide=1)
hello@openetech.com70214022019-10-16 23:38:51 +0530160 ],
161 'Purchase Invoice': [
162 dict(fieldname='document_type', label='Document Type',
163 fieldtype='Data', insert_after='company', print_hide=1, read_only=1
164 ),
165 dict(fieldname='destination_code', label='Destination Code',
166 fieldtype='Data', insert_after='company', print_hide=1, read_only=1
167 ),
168 dict(fieldname='imported_grand_total', label='Imported Grand Total',
169 fieldtype='Data', insert_after='update_auto_repeat_reference', print_hide=1, read_only=1
170 )
171 ],
172 'Purchase Taxes and Charges': [
173 dict(fieldname='tax_rate', label='Tax Rate',
174 fieldtype='Data', insert_after='parenttype', print_hide=1, read_only=0
175 )
176 ],
177 'Supplier': [
178 dict(fieldname='fiscal_code', label='Fiscal Code',
179 fieldtype='Data', insert_after='tax_id', print_hide=1, read_only=1
180 ),
181 dict(fieldname='fiscal_regime', label='Fiscal Regime',
182 fieldtype='Select', insert_after='fiscal_code', print_hide=1, read_only=1,
183 options= "\nRF01\nRF02\nRF04\nRF05\nRF06\nRF07\nRF08\nRF09\nRF10\nRF11\nRF12\nRF13\nRF14\nRF15\nRF16\nRF17\nRF18\nRF19"
184 )
Saurabh9fcfc632019-02-20 13:03:50 +0530185 ]
186 }
Gaurava4aa80f2019-01-06 12:40:28 +0530187
Saurabh9fcfc632019-02-20 13:03:50 +0530188 create_custom_fields(custom_fields, ignore_validate = frappe.flags.in_patch, update=update)
Gauravf1e28e02019-02-13 16:46:24 +0530189
190def setup_report():
Saurabh9fcfc632019-02-20 13:03:50 +0530191 report_name = 'Electronic Invoice Register'
Gauravf1e28e02019-02-13 16:46:24 +0530192
Saurabh9fcfc632019-02-20 13:03:50 +0530193 frappe.db.sql(""" update `tabReport` set disabled = 0 where
194 name = %s """, report_name)
Gauravf1e28e02019-02-13 16:46:24 +0530195
Saurabh9fcfc632019-02-20 13:03:50 +0530196 if not frappe.db.get_value('Custom Role', dict(report=report_name)):
197 frappe.get_doc(dict(
198 doctype='Custom Role',
199 report=report_name,
200 roles= [
201 dict(role='Accounts User'),
202 dict(role='Accounts Manager')
203 ]
204 )).insert()
marination29d7a7e2020-05-27 21:53:01 +0530205
206def add_permissions():
207 doctype = 'Import Supplier Invoice'
208 add_permission(doctype, 'All', 0)
209
210 for role in ('Accounts Manager', 'Accounts User','Purchase User', 'Auditor'):
211 add_permission(doctype, role, 0)
212 update_permission_property(doctype, role, 0, 'print', 1)
213 update_permission_property(doctype, role, 0, 'report', 1)
214
215 if role in ('Accounts Manager', 'Accounts User'):
216 update_permission_property(doctype, role, 0, 'write', 1)
217 update_permission_property(doctype, role, 0, 'create', 1)
218
219 update_permission_property(doctype, 'Accounts Manager', 0, 'delete', 1)
220 add_permission(doctype, 'Accounts Manager', 1)
221 update_permission_property(doctype, 'Accounts Manager', 1, 'write', 1)
222 update_permission_property(doctype, 'Accounts Manager', 1, 'create', 1)