Skip to content

Commit

Permalink
Merge branch 'develop' into tax-breakup-group-by-item
Browse files Browse the repository at this point in the history
  • Loading branch information
deepeshgarg007 authored Sep 16, 2021
2 parents d1a4c73 + c9c8957 commit 5f8c497
Show file tree
Hide file tree
Showing 38 changed files with 707 additions and 127 deletions.
3 changes: 2 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ coverage:
comment:
layout: "diff, files"
require_changes: true

after_n_builds: 3

ignore:
- "erpnext/demo"
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
frappe.ui.form.on('POS Invoice Merge Log', {
setup: function(frm) {
frm.set_query("pos_invoice", "pos_invoices", doc => {
return{
return {
filters: {
'docstatus': 1,
'customer': doc.customer,
'consolidated_invoice': ''
}
}
});
},

merge_invoices_based_on: function(frm) {
frm.set_value('customer', '');
frm.set_value('customer_group', '');
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
"engine": "InnoDB",
"field_order": [
"posting_date",
"customer",
"merge_invoices_based_on",
"column_break_3",
"pos_closing_entry",
"customer",
"customer_group",
"section_break_3",
"pos_invoices",
"references_section",
Expand Down Expand Up @@ -88,12 +90,27 @@
"fieldtype": "Link",
"label": "POS Closing Entry",
"options": "POS Closing Entry"
},
{
"fieldname": "merge_invoices_based_on",
"fieldtype": "Select",
"label": "Merge Invoices Based On",
"options": "Customer\nCustomer Group",
"reqd": 1
},
{
"depends_on": "eval:doc.merge_invoices_based_on == 'Customer Group'",
"fieldname": "customer_group",
"fieldtype": "Link",
"label": "Customer Group",
"mandatory_depends_on": "eval:doc.merge_invoices_based_on == 'Customer Group'",
"options": "Customer Group"
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2020-12-01 11:53:57.267579",
"modified": "2021-09-14 11:17:19.001142",
"modified_by": "Administrator",
"module": "Accounts",
"name": "POS Invoice Merge Log",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def validate(self):
self.validate_pos_invoice_status()

def validate_customer(self):
if self.merge_invoices_based_on == 'Customer Group':
return

for d in self.pos_invoices:
if d.customer != self.customer:
frappe.throw(_("Row #{}: POS Invoice {} is not against customer {}").format(d.idx, d.pos_invoice, self.customer))
Expand Down Expand Up @@ -124,7 +127,7 @@ def merge_pos_invoice_into(self, invoice, data):
found = False
for i in items:
if (i.item_code == item.item_code and not i.serial_no and not i.batch_no and
i.uom == item.uom and i.net_rate == item.net_rate):
i.uom == item.uom and i.net_rate == item.net_rate and i.warehouse == item.warehouse):
found = True
i.qty = i.qty + item.qty

Expand Down Expand Up @@ -172,6 +175,11 @@ def merge_pos_invoice_into(self, invoice, data):
invoice.discount_amount = 0.0
invoice.taxes_and_charges = None
invoice.ignore_pricing_rule = 1
invoice.customer = self.customer

if self.merge_invoices_based_on == 'Customer Group':
invoice.flags.ignore_pos_profile = True
invoice.pos_profile = ''

return invoice

Expand Down Expand Up @@ -228,7 +236,7 @@ def get_all_unconsolidated_invoices():
return pos_invoices

def get_invoice_customer_map(pos_invoices):
# pos_invoice_customer_map = { 'Customer 1': [{}, {}, {}], 'Custoemr 2' : [{}] }
# pos_invoice_customer_map = { 'Customer 1': [{}, {}, {}], 'Customer 2' : [{}] }
pos_invoice_customer_map = {}
for invoice in pos_invoices:
customer = invoice.get('customer')
Expand Down
2 changes: 1 addition & 1 deletion erpnext/accounts/doctype/sales_invoice/sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ def set_pos_fields(self, for_validate=False):
self.account_for_change_amount = frappe.get_cached_value('Company', self.company, 'default_cash_account')

from erpnext.stock.get_item_details import get_pos_profile, get_pos_profile_item_details
if not self.pos_profile:
if not self.pos_profile and not self.flags.ignore_pos_profile:
pos_profile = get_pos_profile(self.company) or {}
if not pos_profile:
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,12 @@ def get_company_currency(filters=None):
def calculate_values(accounts_by_name, gl_entries_by_account, companies, start_date, filters):
for entries in gl_entries_by_account.values():
for entry in entries:
d = accounts_by_name.get(entry.account_name)
if entry.account_number:
account_name = entry.account_number + ' - ' + entry.account_name
else:
account_name = entry.account_name

d = accounts_by_name.get(account_name)
if d:
for company in companies:
# check if posting date is within the period
Expand Down Expand Up @@ -307,7 +312,14 @@ def update_parent_account_names(accounts):
of account_number and suffix of company abbr. This function adds key called
`parent_account_name` which does not have such prefix/suffix.
"""
name_to_account_map = { d.name : d.account_name for d in accounts }
name_to_account_map = {}

for d in accounts:
if d.account_number:
account_name = d.account_number + ' - ' + d.account_name
else:
account_name = d.account_name
name_to_account_map[d.name] = account_name

for account in accounts:
if account.parent_account:
Expand Down Expand Up @@ -420,7 +432,11 @@ def set_gl_entries_by_account(from_date, to_date, root_lft, root_rgt, filters, g
convert_to_presentation_currency(gl_entries, currency_info, filters.get('company'))

for entry in gl_entries:
account_name = entry.account_name
if entry.account_number:
account_name = entry.account_number + ' - ' + entry.account_name
else:
account_name = entry.account_name

validate_entries(account_name, entry, accounts_by_name, accounts)
gl_entries_by_account.setdefault(account_name, []).append(entry)

Expand Down Expand Up @@ -491,7 +507,12 @@ def filter_accounts(accounts, depth=10):
parent_children_map = {}
accounts_by_name = {}
for d in accounts:
accounts_by_name[d.account_name] = d
if d.account_number:
account_name = d.account_number + ' - ' + d.account_name
else:
account_name = d.account_name
accounts_by_name[account_name] = d

parent_children_map.setdefault(d.parent_account or None, []).append(d)

filtered_accounts = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
frappe.query_reports["Unpaid Expense Claim"] = {
"filters": [
{
"fieldname":"employee",
"fieldname": "employee",
"label": __("Employee"),
"fieldtype": "Link"
"fieldtype": "Link",
"options": "Employee"
}
]
}
4 changes: 2 additions & 2 deletions erpnext/buying/doctype/buying_settings/buying_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"fieldname": "supp_master_name",
"fieldtype": "Select",
"label": "Supplier Naming By",
"options": "Supplier Name\nNaming Series"
"options": "Supplier Name\nNaming Series\nAuto Name"
},
{
"fieldname": "supplier_group",
Expand Down Expand Up @@ -123,7 +123,7 @@
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2021-06-24 10:38:28.934525",
"modified": "2021-09-08 19:26:23.548837",
"modified_by": "Administrator",
"module": "Buying",
"name": "Buying Settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,10 @@ def get_item_from_material_requests_based_on_supplier(source_name, target_doc =

@frappe.whitelist()
def get_supplier_tag():
if not frappe.cache().hget("Supplier", "Tags"):
filters = {"document_type": "Supplier"}
tags = list(set(tag.tag for tag in frappe.get_all("Tag Link", filters=filters, fields=["tag"]) if tag))
frappe.cache().hset("Supplier", "Tags", tags)
filters = {"document_type": "Supplier"}
tags = list(set(tag.tag for tag in frappe.get_all("Tag Link", filters=filters, fields=["tag"]) if tag))

return frappe.cache().hget("Supplier", "Tags")
return tags

@frappe.whitelist()
@frappe.validate_and_sanitize_search_inputs
Expand Down
6 changes: 4 additions & 2 deletions erpnext/buying/doctype/supplier/supplier.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
delete_contact_and_address,
load_address_and_contact,
)
from frappe.model.naming import set_name_by_naming_series
from frappe.model.naming import set_name_by_naming_series, set_name_from_naming_options

from erpnext.accounts.party import get_dashboard_info, validate_party_accounts
from erpnext.utilities.transaction_base import TransactionBase
Expand Down Expand Up @@ -40,8 +40,10 @@ def autoname(self):
supp_master_name = frappe.defaults.get_global_default('supp_master_name')
if supp_master_name == 'Supplier Name':
self.name = self.supplier_name
else:
elif supp_master_name == 'Naming Series':
set_name_by_naming_series(self)
else:
self.name = set_name_from_naming_options(frappe.get_meta(self.doctype).autoname, self)

def on_update(self):
if not self.naming_series:
Expand Down
2 changes: 1 addition & 1 deletion erpnext/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@
"Purchase Receipt Item", "Stock Entry Detail", "Payment Entry Deduction", "Sales Taxes and Charges", "Purchase Taxes and Charges", "Shipping Rule",
"Landed Cost Item", "Asset Value Adjustment", "Loyalty Program", "Fee Schedule", "Fee Structure", "Stock Reconciliation",
"Travel Request", "Fees", "POS Profile", "Opening Invoice Creation Tool", "Opening Invoice Creation Tool Item", "Subscription",
"Subscription Plan"
"Subscription Plan", "POS Invoice", "POS Invoice Item"
]

regional_overrides = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ frappe.ui.form.on('Maintenance Schedule', {
},
refresh: function (frm) {
setTimeout(() => {
frm.toggle_display('generate_schedule', !(frm.is_new()));
frm.toggle_display('generate_schedule', !(frm.is_new() || frm.doc.docstatus));
frm.toggle_display('schedule', !(frm.is_new()));
}, 10);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
class MaintenanceSchedule(TransactionBase):
@frappe.whitelist()
def generate_schedule(self):
if self.docstatus != 0:
return
self.set('schedules', [])
frappe.db.sql("""delete from `tabMaintenance Schedule Detail`
where parent=%s""", (self.name))
count = 1
for d in self.get('items'):
self.validate_maintenance_detail()
Expand Down
12 changes: 10 additions & 2 deletions erpnext/manufacturing/doctype/bom/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,14 @@ def calculate_op_cost(self, update_hour_rate = False):
if d.workstation:
self.update_rate_and_time(d, update_hour_rate)

self.operating_cost += flt(d.operating_cost)
self.base_operating_cost += flt(d.base_operating_cost)
operating_cost = d.operating_cost
base_operating_cost = d.base_operating_cost
if d.set_cost_based_on_bom_qty:
operating_cost = flt(d.cost_per_unit) * flt(self.quantity)
base_operating_cost = flt(d.base_cost_per_unit) * flt(self.quantity)

self.operating_cost += flt(operating_cost)
self.base_operating_cost += flt(base_operating_cost)

def update_rate_and_time(self, row, update_hour_rate = False):
if not row.hour_rate or update_hour_rate:
Expand All @@ -535,6 +541,8 @@ def update_rate_and_time(self, row, update_hour_rate = False):
row.base_hour_rate = flt(row.hour_rate) * flt(self.conversion_rate)
row.operating_cost = flt(row.hour_rate) * flt(row.time_in_mins) / 60.0
row.base_operating_cost = flt(row.operating_cost) * flt(self.conversion_rate)
row.cost_per_unit = row.operating_cost / (row.batch_size or 1.0)
row.base_cost_per_unit = row.base_operating_cost / (row.batch_size or 1.0)

if update_hour_rate:
row.db_update()
Expand Down
18 changes: 18 additions & 0 deletions erpnext/manufacturing/doctype/bom/test_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,24 @@ def test_bom_cost(self):
self.assertAlmostEqual(bom.base_raw_material_cost, base_raw_material_cost)
self.assertAlmostEqual(bom.base_total_cost, base_raw_material_cost + base_op_cost)

def test_bom_cost_with_batch_size(self):
bom = frappe.copy_doc(test_records[2])
bom.docstatus = 0
op_cost = 0.0
for op_row in bom.operations:
op_row.docstatus = 0
op_row.batch_size = 2
op_row.set_cost_based_on_bom_qty = 1
op_cost += op_row.operating_cost

bom.save()

for op_row in bom.operations:
self.assertAlmostEqual(op_row.cost_per_unit, op_row.operating_cost / 2)

self.assertAlmostEqual(bom.operating_cost, op_cost/2)
bom.delete()

def test_bom_cost_multi_uom_multi_currency_based_on_price_list(self):
frappe.db.set_value("Price List", "_Test Price List", "price_not_uom_dependent", 1)
for item_code, rate in (("_Test Item", 3600), ("_Test Item Home Desktop Manufactured", 3000)):
Expand Down
Loading

0 comments on commit 5f8c497

Please sign in to comment.