Merge pull request #30774 from ankush/postgres/stock
fix(postgres): minimum required changes for postgres builds
This commit is contained in:
commit
8d20da9b7a
@ -163,10 +163,15 @@ def get_party_details(party, party_type, args=None):
|
|||||||
def get_tax_template(posting_date, args):
|
def get_tax_template(posting_date, args):
|
||||||
"""Get matching tax rule"""
|
"""Get matching tax rule"""
|
||||||
args = frappe._dict(args)
|
args = frappe._dict(args)
|
||||||
|
from_date = to_date = posting_date
|
||||||
|
if not posting_date:
|
||||||
|
from_date = "1900-01-01"
|
||||||
|
to_date = "4000-01-01"
|
||||||
|
|
||||||
conditions = [
|
conditions = [
|
||||||
"""(from_date is null or from_date <= '{0}')
|
"""(from_date is null or from_date <= '{0}')
|
||||||
and (to_date is null or to_date >= '{0}')""".format(
|
and (to_date is null or to_date >= '{1}')""".format(
|
||||||
posting_date
|
from_date, to_date
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -831,9 +831,9 @@ def get_party_shipping_address(doctype, name):
|
|||||||
"where "
|
"where "
|
||||||
"dl.link_doctype=%s "
|
"dl.link_doctype=%s "
|
||||||
"and dl.link_name=%s "
|
"and dl.link_name=%s "
|
||||||
'and dl.parenttype="Address" '
|
"and dl.parenttype='Address' "
|
||||||
"and ifnull(ta.disabled, 0) = 0 and"
|
"and ifnull(ta.disabled, 0) = 0 and"
|
||||||
'(ta.address_type="Shipping" or ta.is_shipping_address=1) '
|
"(ta.address_type='Shipping' or ta.is_shipping_address=1) "
|
||||||
"order by ta.is_shipping_address desc, ta.address_type desc limit 1",
|
"order by ta.is_shipping_address desc, ta.address_type desc limit 1",
|
||||||
(doctype, name),
|
(doctype, name),
|
||||||
)
|
)
|
||||||
@ -881,11 +881,11 @@ def get_default_contact(doctype, name):
|
|||||||
"""
|
"""
|
||||||
SELECT dl.parent, c.is_primary_contact, c.is_billing_contact
|
SELECT dl.parent, c.is_primary_contact, c.is_billing_contact
|
||||||
FROM `tabDynamic Link` dl
|
FROM `tabDynamic Link` dl
|
||||||
INNER JOIN tabContact c ON c.name = dl.parent
|
INNER JOIN `tabContact` c ON c.name = dl.parent
|
||||||
WHERE
|
WHERE
|
||||||
dl.link_doctype=%s AND
|
dl.link_doctype=%s AND
|
||||||
dl.link_name=%s AND
|
dl.link_name=%s AND
|
||||||
dl.parenttype = "Contact"
|
dl.parenttype = 'Contact'
|
||||||
ORDER BY is_primary_contact DESC, is_billing_contact DESC
|
ORDER BY is_primary_contact DESC, is_billing_contact DESC
|
||||||
""",
|
""",
|
||||||
(doctype, name),
|
(doctype, name),
|
||||||
|
@ -54,11 +54,11 @@ class Opportunity(TransactionBase):
|
|||||||
self.calculate_totals()
|
self.calculate_totals()
|
||||||
|
|
||||||
def map_fields(self):
|
def map_fields(self):
|
||||||
for field in self.meta.fields:
|
for field in self.meta.get_valid_columns():
|
||||||
if not self.get(field.fieldname):
|
if not self.get(field) and frappe.db.field_exists(self.opportunity_from, field):
|
||||||
try:
|
try:
|
||||||
value = frappe.db.get_value(self.opportunity_from, self.party_name, field.fieldname)
|
value = frappe.db.get_value(self.opportunity_from, self.party_name, field)
|
||||||
frappe.db.set(self, field.fieldname, value)
|
frappe.db.set(self, field, value)
|
||||||
except Exception:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -753,7 +753,7 @@ class BOM(WebsiteGenerator):
|
|||||||
bom_item.include_item_in_manufacturing,
|
bom_item.include_item_in_manufacturing,
|
||||||
bom_item.sourced_by_supplier,
|
bom_item.sourced_by_supplier,
|
||||||
bom_item.stock_qty / ifnull(bom.quantity, 1) AS qty_consumed_per_unit
|
bom_item.stock_qty / ifnull(bom.quantity, 1) AS qty_consumed_per_unit
|
||||||
FROM `tabBOM Explosion Item` bom_item, tabBOM bom
|
FROM `tabBOM Explosion Item` bom_item, `tabBOM` bom
|
||||||
WHERE
|
WHERE
|
||||||
bom_item.parent = bom.name
|
bom_item.parent = bom.name
|
||||||
AND bom.name = %s
|
AND bom.name = %s
|
||||||
|
@ -1219,7 +1219,7 @@ def make_fixtures(company=None):
|
|||||||
try:
|
try:
|
||||||
doc = frappe.get_doc(d)
|
doc = frappe.get_doc(d)
|
||||||
doc.flags.ignore_permissions = True
|
doc.flags.ignore_permissions = True
|
||||||
doc.insert()
|
doc.insert(ignore_if_duplicate=True)
|
||||||
except frappe.NameError:
|
except frappe.NameError:
|
||||||
frappe.clear_messages()
|
frappe.clear_messages()
|
||||||
except frappe.DuplicateEntryError:
|
except frappe.DuplicateEntryError:
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
from frappe.query_builder import Criterion
|
||||||
|
from frappe.query_builder.functions import Cast_
|
||||||
from frappe.utils import getdate
|
from frappe.utils import getdate
|
||||||
|
|
||||||
|
|
||||||
@ -48,35 +50,57 @@ class ItemPrice(Document):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def check_duplicates(self):
|
def check_duplicates(self):
|
||||||
conditions = (
|
|
||||||
"""where item_code = %(item_code)s and price_list = %(price_list)s and name != %(name)s"""
|
|
||||||
)
|
|
||||||
|
|
||||||
for field in [
|
item_price = frappe.qb.DocType("Item Price")
|
||||||
|
|
||||||
|
query = (
|
||||||
|
frappe.qb.from_(item_price)
|
||||||
|
.select(item_price.price_list_rate)
|
||||||
|
.where(
|
||||||
|
(item_price.item_code == self.item_code)
|
||||||
|
& (item_price.price_list == self.price_list)
|
||||||
|
& (item_price.name != self.name)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
data_fields = (
|
||||||
"uom",
|
"uom",
|
||||||
"valid_from",
|
"valid_from",
|
||||||
"valid_upto",
|
"valid_upto",
|
||||||
"packing_unit",
|
|
||||||
"customer",
|
"customer",
|
||||||
"supplier",
|
"supplier",
|
||||||
"batch_no",
|
"batch_no",
|
||||||
]:
|
|
||||||
if self.get(field):
|
|
||||||
conditions += " and {0} = %({0})s ".format(field)
|
|
||||||
else:
|
|
||||||
conditions += "and (isnull({0}) or {0} = '')".format(field)
|
|
||||||
|
|
||||||
price_list_rate = frappe.db.sql(
|
|
||||||
"""
|
|
||||||
select price_list_rate
|
|
||||||
from `tabItem Price`
|
|
||||||
{conditions}
|
|
||||||
""".format(
|
|
||||||
conditions=conditions
|
|
||||||
),
|
|
||||||
self.as_dict(),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
number_fields = ["packing_unit"]
|
||||||
|
|
||||||
|
for field in data_fields:
|
||||||
|
if self.get(field):
|
||||||
|
query = query.where(item_price[field] == self.get(field))
|
||||||
|
else:
|
||||||
|
query = query.where(
|
||||||
|
Criterion.any(
|
||||||
|
[
|
||||||
|
item_price[field].isnull(),
|
||||||
|
Cast_(item_price[field], "varchar") == "",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
for field in number_fields:
|
||||||
|
if self.get(field):
|
||||||
|
query = query.where(item_price[field] == self.get(field))
|
||||||
|
else:
|
||||||
|
query = query.where(
|
||||||
|
Criterion.any(
|
||||||
|
[
|
||||||
|
item_price[field].isnull(),
|
||||||
|
item_price[field] == 0,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
price_list_rate = query.run(as_dict=True)
|
||||||
|
|
||||||
if price_list_rate:
|
if price_list_rate:
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
_(
|
_(
|
||||||
|
@ -1167,7 +1167,7 @@ class StockEntry(StockController):
|
|||||||
from `tabItem` i LEFT JOIN `tabItem Default` id ON i.name=id.parent and id.company=%s
|
from `tabItem` i LEFT JOIN `tabItem Default` id ON i.name=id.parent and id.company=%s
|
||||||
where i.name=%s
|
where i.name=%s
|
||||||
and i.disabled=0
|
and i.disabled=0
|
||||||
and (i.end_of_life is null or i.end_of_life='0000-00-00' or i.end_of_life > %s)""",
|
and (i.end_of_life is null or i.end_of_life<'1900-01-01' or i.end_of_life > %s)""",
|
||||||
(self.company, args.get("item_code"), nowdate()),
|
(self.company, args.get("item_code"), nowdate()),
|
||||||
as_dict=1,
|
as_dict=1,
|
||||||
)
|
)
|
||||||
|
@ -8,9 +8,8 @@ from typing import Optional, Set, Tuple
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.meta import get_field_precision
|
from frappe.model.meta import get_field_precision
|
||||||
from frappe.query_builder.functions import Sum
|
from frappe.query_builder.functions import CombineDatetime, Sum
|
||||||
from frappe.utils import cint, cstr, flt, get_link_to_form, getdate, now, nowdate
|
from frappe.utils import cint, cstr, flt, get_link_to_form, getdate, now, nowdate
|
||||||
from pypika import CustomFunction
|
|
||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
from erpnext.stock.doctype.bin.bin import update_qty as update_bin_qty
|
from erpnext.stock.doctype.bin.bin import update_qty as update_bin_qty
|
||||||
@ -1158,16 +1157,15 @@ def get_batch_incoming_rate(
|
|||||||
item_code, warehouse, batch_no, posting_date, posting_time, creation=None
|
item_code, warehouse, batch_no, posting_date, posting_time, creation=None
|
||||||
):
|
):
|
||||||
|
|
||||||
Timestamp = CustomFunction("timestamp", ["date", "time"])
|
|
||||||
|
|
||||||
sle = frappe.qb.DocType("Stock Ledger Entry")
|
sle = frappe.qb.DocType("Stock Ledger Entry")
|
||||||
|
|
||||||
timestamp_condition = Timestamp(sle.posting_date, sle.posting_time) < Timestamp(
|
timestamp_condition = CombineDatetime(sle.posting_date, sle.posting_time) < CombineDatetime(
|
||||||
posting_date, posting_time
|
posting_date, posting_time
|
||||||
)
|
)
|
||||||
if creation:
|
if creation:
|
||||||
timestamp_condition |= (
|
timestamp_condition |= (
|
||||||
Timestamp(sle.posting_date, sle.posting_time) == Timestamp(posting_date, posting_time)
|
CombineDatetime(sle.posting_date, sle.posting_time)
|
||||||
|
== CombineDatetime(posting_date, posting_time)
|
||||||
) & (sle.creation < creation)
|
) & (sle.creation < creation)
|
||||||
|
|
||||||
batch_details = (
|
batch_details = (
|
||||||
|
@ -7,6 +7,7 @@ from typing import Dict, Optional
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
|
from frappe.query_builder.functions import CombineDatetime
|
||||||
from frappe.utils import cstr, flt, get_link_to_form, nowdate, nowtime
|
from frappe.utils import cstr, flt, get_link_to_form, nowdate, nowtime
|
||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
@ -143,12 +144,10 @@ def get_stock_balance(
|
|||||||
|
|
||||||
|
|
||||||
def get_serial_nos_data_after_transactions(args):
|
def get_serial_nos_data_after_transactions(args):
|
||||||
from pypika import CustomFunction
|
|
||||||
|
|
||||||
serial_nos = set()
|
serial_nos = set()
|
||||||
args = frappe._dict(args)
|
args = frappe._dict(args)
|
||||||
sle = frappe.qb.DocType("Stock Ledger Entry")
|
sle = frappe.qb.DocType("Stock Ledger Entry")
|
||||||
Timestamp = CustomFunction("timestamp", ["date", "time"])
|
|
||||||
|
|
||||||
stock_ledger_entries = (
|
stock_ledger_entries = (
|
||||||
frappe.qb.from_(sle)
|
frappe.qb.from_(sle)
|
||||||
@ -157,7 +156,8 @@ def get_serial_nos_data_after_transactions(args):
|
|||||||
(sle.item_code == args.item_code)
|
(sle.item_code == args.item_code)
|
||||||
& (sle.warehouse == args.warehouse)
|
& (sle.warehouse == args.warehouse)
|
||||||
& (
|
& (
|
||||||
Timestamp(sle.posting_date, sle.posting_time) < Timestamp(args.posting_date, args.posting_time)
|
CombineDatetime(sle.posting_date, sle.posting_time)
|
||||||
|
< CombineDatetime(args.posting_date, args.posting_time)
|
||||||
)
|
)
|
||||||
& (sle.is_cancelled == 0)
|
& (sle.is_cancelled == 0)
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user