Fix cost center not getting pulled in DN and SINV (#8878)
* Fixes for getting selling cost center instead of company's default cost center. * fix error in update_item
This commit is contained in:
parent
67ddcf9d32
commit
3b04b030eb
@ -330,7 +330,7 @@ class SalesInvoice(SellingController):
|
||||
frappe.throw(_("Debit To account must be a Receivable account"))
|
||||
|
||||
self.party_account_currency = account.account_currency
|
||||
|
||||
|
||||
def clear_unallocated_mode_of_payments(self):
|
||||
self.set("payments", self.get("payments", {"amount": ["not in", [0, None, ""]]}))
|
||||
|
||||
@ -551,7 +551,7 @@ class SalesInvoice(SellingController):
|
||||
def make_gl_entries(self, gl_entries=None, repost_future_gle=True, from_repost=False):
|
||||
if not self.grand_total:
|
||||
return
|
||||
|
||||
|
||||
if not gl_entries:
|
||||
gl_entries = self.get_gl_entries()
|
||||
|
||||
@ -697,7 +697,7 @@ class SalesInvoice(SellingController):
|
||||
else payment_mode.amount
|
||||
}, payment_mode_account_currency)
|
||||
)
|
||||
|
||||
|
||||
def make_gle_for_change_amount(self, gl_entries):
|
||||
if cint(self.is_pos) and self.change_amount:
|
||||
if self.account_for_change_amount:
|
||||
@ -714,7 +714,7 @@ class SalesInvoice(SellingController):
|
||||
"against_voucher_type": self.doctype
|
||||
}, self.party_account_currency)
|
||||
)
|
||||
|
||||
|
||||
gl_entries.append(
|
||||
self.get_gl_dict({
|
||||
"account": self.account_for_change_amount,
|
||||
@ -724,7 +724,7 @@ class SalesInvoice(SellingController):
|
||||
)
|
||||
else:
|
||||
frappe.throw(_("Select change amount account"), title="Mandatory Field")
|
||||
|
||||
|
||||
def make_write_off_gl_entry(self, gl_entries):
|
||||
# write off entries, applicable if only pos
|
||||
if self.write_off_account and self.write_off_amount:
|
||||
@ -808,7 +808,7 @@ def make_delivery_note(source_name, target_doc=None):
|
||||
def update_item(source_doc, target_doc, source_parent):
|
||||
target_doc.qty = flt(source_doc.qty) - flt(source_doc.delivered_qty)
|
||||
target_doc.stock_qty = target_doc.qty * flt(source_doc.conversion_factor)
|
||||
|
||||
|
||||
target_doc.base_amount = target_doc.qty * flt(source_doc.base_rate)
|
||||
target_doc.amount = target_doc.qty * flt(source_doc.rate)
|
||||
|
||||
@ -826,7 +826,8 @@ def make_delivery_note(source_name, target_doc=None):
|
||||
"parent": "against_sales_invoice",
|
||||
"serial_no": "serial_no",
|
||||
"sales_order": "against_sales_order",
|
||||
"so_detail": "so_detail"
|
||||
"so_detail": "so_detail",
|
||||
"cost_center": "cost_center"
|
||||
},
|
||||
"postprocess": update_item,
|
||||
"condition": lambda doc: doc.delivered_by_supplier!=1
|
||||
@ -855,4 +856,4 @@ def make_sales_return(source_name, target_doc=None):
|
||||
def set_account_for_mode_of_payment(self):
|
||||
for data in self.payments:
|
||||
if not data.account:
|
||||
data.account = get_bank_cash_account(data.mode_of_payment, self.company).get("account")
|
||||
data.account = get_bank_cash_account(data.mode_of_payment, self.company).get("account")
|
||||
|
@ -175,7 +175,7 @@ class SalesOrder(SellingController):
|
||||
self.update_prevdoc_status('cancel')
|
||||
|
||||
frappe.db.set(self, 'status', 'Cancelled')
|
||||
|
||||
|
||||
def update_project(self):
|
||||
project_list = []
|
||||
if self.project:
|
||||
@ -183,7 +183,7 @@ class SalesOrder(SellingController):
|
||||
project.flags.dont_sync_tasks = True
|
||||
project.update_sales_costing()
|
||||
project.save()
|
||||
project_list.append(self.project)
|
||||
project_list.append(self.project)
|
||||
|
||||
def check_credit_limit(self):
|
||||
from erpnext.selling.doctype.customer.customer import check_credit_limit
|
||||
@ -427,6 +427,11 @@ def make_delivery_note(source_name, target_doc=None):
|
||||
target.amount = (flt(source.qty) - flt(source.delivered_qty)) * flt(source.rate)
|
||||
target.qty = flt(source.qty) - flt(source.delivered_qty)
|
||||
|
||||
item = frappe.db.get_value("Item", target.item_code, ["item_group", "selling_cost_center"], as_dict=1)
|
||||
target.cost_center = frappe.db.get_value("Project", source_parent.project, "cost_center") \
|
||||
or item.selling_cost_center \
|
||||
or frappe.db.get_value("Item Group", item.item_group, "default_cost_center")
|
||||
|
||||
target_doc = get_mapped_doc("Sales Order", source_name, {
|
||||
"Sales Order": {
|
||||
"doctype": "Delivery Note",
|
||||
|
@ -398,7 +398,8 @@ def make_sales_invoice(source_name, target_doc=None):
|
||||
"parent": "delivery_note",
|
||||
"so_detail": "so_detail",
|
||||
"against_sales_order": "sales_order",
|
||||
"serial_no": "serial_no"
|
||||
"serial_no": "serial_no",
|
||||
"cost_center": "cost_center"
|
||||
},
|
||||
"postprocess": update_item,
|
||||
"filter": lambda d: abs(d.qty) - abs(invoiced_qty_map.get(d.name, 0))<=0
|
||||
|
Loading…
Reference in New Issue
Block a user