Gaurav | a4aa80f | 2019-01-06 12:40:28 +0530 | [diff] [blame] | 1 | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
| 2 | # License: GNU General Public License v3. See license.txt |
| 3 | # coding=utf-8 |
| 4 | |
| 5 | from __future__ import unicode_literals |
| 6 | |
| 7 | import frappe |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 8 | from frappe import _ |
Gaurav | a4aa80f | 2019-01-06 12:40:28 +0530 | [diff] [blame] | 9 | from frappe.custom.doctype.custom_field.custom_field import create_custom_fields |
marination | 29d7a7e | 2020-05-27 21:53:01 +0530 | [diff] [blame] | 10 | from frappe.permissions import add_permission, update_permission_property |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 11 | from erpnext.regional.italy import fiscal_regimes, tax_exemption_reasons, mode_of_payment_codes, vat_collectability_options |
Gaurav | a4aa80f | 2019-01-06 12:40:28 +0530 | [diff] [blame] | 12 | |
| 13 | def setup(company=None, patch=True): |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 14 | make_custom_fields() |
| 15 | setup_report() |
marination | 29d7a7e | 2020-05-27 21:53:01 +0530 | [diff] [blame] | 16 | add_permissions() |
Gaurav | a4aa80f | 2019-01-06 12:40:28 +0530 | [diff] [blame] | 17 | |
| 18 | def make_custom_fields(update=True): |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 19 | invoice_item_fields = [ |
| 20 | dict(fieldname='tax_rate', label='Tax Rate', |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 21 | 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") |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 29 | ] |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 30 | |
Rohit Waghchaure | 22ebaf1 | 2019-03-07 15:18:49 +0530 | [diff] [blame] | 31 | 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 Waghchaure | 1b7059b | 2019-03-12 17:44:29 +0530 | [diff] [blame] | 37 | print_hide=1, allow_on_submit=1, fetch_if_empty= 1, read_only=1, no_copy=1), |
Rohit Waghchaure | 22ebaf1 | 2019-03-07 15:18:49 +0530 | [diff] [blame] | 38 | 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 Waghchaure | 1b7059b | 2019-03-12 17:44:29 +0530 | [diff] [blame] | 44 | print_hide=1, allow_on_submit=1, fetch_if_empty= 1, read_only=1, no_copy=1) |
Rohit Waghchaure | 22ebaf1 | 2019-03-07 15:18:49 +0530 | [diff] [blame] | 45 | ] |
| 46 | |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 47 | 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, |
Gaurav | b30a9b1 | 2019-03-01 12:33:19 +0530 | [diff] [blame] | 53 | options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), fiscal_regimes))), |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 54 | 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, |
Gaurav | b30a9b1 | 2019-03-01 12:33:19 +0530 | [diff] [blame] | 58 | options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), vat_collectability_options))), |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 59 | 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', |
Gaurav | b30a9b1 | 2019-03-01 12:33:19 +0530 | [diff] [blame] | 78 | options="\n" + "\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), tax_exemption_reasons))), |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 79 | 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, |
Gaurav | b30a9b1 | 2019-03-01 12:33:19 +0530 | [diff] [blame] | 101 | options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), mode_of_payment_codes))) |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 102 | ], |
| 103 | 'Payment Schedule': [ |
| 104 | dict(fieldname='mode_of_payment_code', label='Code', |
| 105 | fieldtype='Select', insert_after='mode_of_payment', print_hide=1, |
Gaurav | b30a9b1 | 2019-03-01 12:33:19 +0530 | [diff] [blame] | 106 | options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), mode_of_payment_codes)), |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 107 | 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"), |
Gaurav | b30a9b1 | 2019-03-01 12:33:19 +0530 | [diff] [blame] | 111 | dict(fieldname='bank_account_name', label='Bank Name', |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 112 | fieldtype='Data', insert_after='bank_account', print_hide=1, |
Gaurav | b30a9b1 | 2019-03-01 12:33:19 +0530 | [diff] [blame] | 113 | fetch_from="bank_account.bank", read_only=1), |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 114 | 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), |
Gaurav | b30a9b1 | 2019-03-01 12:33:19 +0530 | [diff] [blame] | 120 | 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), |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 123 | ], |
| 124 | "Sales Invoice": [ |
| 125 | dict(fieldname='vat_collectability', label='VAT Collectability', |
| 126 | fieldtype='Select', insert_after='taxes_and_charges', print_hide=1, |
Gaurav | b30a9b1 | 2019-03-01 12:33:19 +0530 | [diff] [blame] | 127 | options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), vat_collectability_options)), |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 128 | fetch_from="company.vat_collectability"), |
| 129 | dict(fieldname='sb_e_invoicing_reference', label='E-Invoicing', |
Saqib Ansari | cee3670 | 2021-02-01 15:45:26 +0530 | [diff] [blame] | 130 | fieldtype='Section Break', insert_after='against_income_account', print_hide=1), |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 131 | dict(fieldname='company_fiscal_code', label='Company Fiscal Code', |
Sagar Vora | ba76f87 | 2021-03-29 20:18:45 +0530 | [diff] [blame] | 132 | fieldtype='Data', insert_after='sb_e_invoicing_reference', print_hide=1, read_only=1, |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 133 | fetch_from="company.fiscal_code"), |
| 134 | dict(fieldname='company_fiscal_regime', label='Company Fiscal Regime', |
| 135 | fieldtype='Data', insert_after='company_fiscal_code', print_hide=1, read_only=1, |
| 136 | fetch_from="company.fiscal_regime"), |
| 137 | dict(fieldname='cb_e_invoicing_reference', fieldtype='Column Break', |
| 138 | insert_after='company_fiscal_regime', print_hide=1), |
| 139 | dict(fieldname='customer_fiscal_code', label='Customer Fiscal Code', |
| 140 | fieldtype='Data', insert_after='cb_e_invoicing_reference', read_only=1, |
| 141 | fetch_from="customer.fiscal_code"), |
Saqib Ansari | 032246d | 2021-04-09 12:08:24 +0530 | [diff] [blame] | 142 | dict(fieldname='type_of_document', label='Type of Document', |
| 143 | fieldtype='Select', insert_after='customer_fiscal_code', |
| 144 | options='\nTD01\nTD02\nTD03\nTD04\nTD05\nTD06\nTD16\nTD17\nTD18\nTD19\nTD20\nTD21\nTD22\nTD23\nTD24\nTD25\nTD26\nTD27'), |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 145 | ], |
| 146 | 'Purchase Invoice Item': invoice_item_fields, |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 147 | 'Sales Order Item': invoice_item_fields, |
| 148 | 'Delivery Note Item': invoice_item_fields, |
Rohit Waghchaure | 22ebaf1 | 2019-03-07 15:18:49 +0530 | [diff] [blame] | 149 | 'Sales Invoice Item': invoice_item_fields + customer_po_fields, |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 150 | '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, |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 154 | 'Address': [ |
| 155 | dict(fieldname='country_code', label='Country Code', |
Rohit Waghchaure | 74cfe57 | 2019-02-26 20:08:26 +0530 | [diff] [blame] | 156 | fieldtype='Data', insert_after='country', print_hide=1, read_only=0, |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 157 | fetch_from="country.code"), |
| 158 | dict(fieldname='state_code', label='State Code', |
| 159 | fieldtype='Data', insert_after='state', print_hide=1) |
hello@openetech.com | 7021402 | 2019-10-16 23:38:51 +0530 | [diff] [blame] | 160 | ], |
| 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 | ) |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 185 | ] |
| 186 | } |
Gaurav | a4aa80f | 2019-01-06 12:40:28 +0530 | [diff] [blame] | 187 | |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 188 | create_custom_fields(custom_fields, ignore_validate = frappe.flags.in_patch, update=update) |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 189 | |
| 190 | def setup_report(): |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 191 | report_name = 'Electronic Invoice Register' |
barredterra | 1521b31 | 2021-03-03 12:33:48 +0100 | [diff] [blame] | 192 | frappe.db.set_value("Report", report_name, "disabled", 0) |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 193 | |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 194 | if not frappe.db.get_value('Custom Role', dict(report=report_name)): |
| 195 | frappe.get_doc(dict( |
| 196 | doctype='Custom Role', |
| 197 | report=report_name, |
| 198 | roles= [ |
| 199 | dict(role='Accounts User'), |
| 200 | dict(role='Accounts Manager') |
| 201 | ] |
| 202 | )).insert() |
marination | 29d7a7e | 2020-05-27 21:53:01 +0530 | [diff] [blame] | 203 | |
| 204 | def add_permissions(): |
| 205 | doctype = 'Import Supplier Invoice' |
| 206 | add_permission(doctype, 'All', 0) |
| 207 | |
| 208 | for role in ('Accounts Manager', 'Accounts User','Purchase User', 'Auditor'): |
| 209 | add_permission(doctype, role, 0) |
| 210 | update_permission_property(doctype, role, 0, 'print', 1) |
| 211 | update_permission_property(doctype, role, 0, 'report', 1) |
| 212 | |
| 213 | if role in ('Accounts Manager', 'Accounts User'): |
| 214 | update_permission_property(doctype, role, 0, 'write', 1) |
| 215 | update_permission_property(doctype, role, 0, 'create', 1) |
| 216 | |
| 217 | update_permission_property(doctype, 'Accounts Manager', 0, 'delete', 1) |
| 218 | add_permission(doctype, 'Accounts Manager', 1) |
| 219 | update_permission_property(doctype, 'Accounts Manager', 1, 'write', 1) |
Sagar Vora | ba76f87 | 2021-03-29 20:18:45 +0530 | [diff] [blame] | 220 | update_permission_property(doctype, 'Accounts Manager', 1, 'create', 1) |